//package info.unterstein.hagen.moderne.ea6.a3; import java.util.HashMap; /** * Enables a more complex and generic caching aspect which can be extended to be * used in several use cases. * * @author Johannes Unterstein * @param * the class of the keys * @param * the class of the cached values */ public abstract aspect CacheAspect { private HashMap cache; public abstract pointcut cachePoint(Object key); V around(Object key) : cachePoint(key) { if (this.cache == null) { this.cache = new HashMap(); } V result; if (this.cache.containsKey(key)) { result = this.cache.get(key); } else { result = proceed(key); this.cache.put(key, result); } Object o = this.cache; return result; } }