You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractCache.aj 781B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package testing;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. public abstract aspect AbstractCache<Key,Value> {
  5. public abstract pointcut cachePoint(Key key);
  6. private Map<Object,Object> cache = new HashMap<Object,Object>();
  7. private Integer hitCount = 0;
  8. private Integer missCount = 0;
  9. Value around(Key key) : cachePoint(key){
  10. Value value = get(key);
  11. if(value == null){
  12. value = proceed(key);
  13. put(key,value);
  14. missCount++;
  15. } else {
  16. hitCount++;
  17. }
  18. return value;
  19. }
  20. @SuppressWarnings("unchecked")
  21. private Value get(Key key){
  22. return (Value) cache.get(key);
  23. }
  24. private void put(Key key, Value value) {
  25. cache.put(key, value);
  26. }
  27. public Integer getHitCount() {
  28. return hitCount;
  29. }
  30. public Integer getMissCount() {
  31. return missCount;
  32. }
  33. }