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.

CacheAspect.java 911B

1234567891011121314151617181920212223242526272829303132333435
  1. //package info.unterstein.hagen.moderne.ea6.a3;
  2. import java.util.HashMap;
  3. /**
  4. * Enables a more complex and generic caching aspect which can be extended to
  5. be
  6. * used in several use cases.
  7. *
  8. * @author <a href="mailto:unterstein@me.com">Johannes Unterstein</a>
  9. * @param <k>
  10. * the class of the keys
  11. * @param <V>
  12. * the class of the cached values
  13. */
  14. public abstract aspect CacheAspect<V> {
  15. private HashMap<Object, V> cache;
  16. public abstract pointcut cachePoint(Object key);
  17. V around(Object key) : cachePoint(key) {
  18. if (this.cache == null) {
  19. this.cache = new HashMap<Object, V>();
  20. }
  21. V result;
  22. if (this.cache.containsKey(key)) {
  23. result = this.cache.get(key);
  24. } else {
  25. result = proceed(key);
  26. this.cache.put(key, result);
  27. }
  28. Object o = this.cache;
  29. return result;
  30. }
  31. }