aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs1612/pr349398/CacheAspect.java
blob: 3240327b6b82e669f037ca3efa032c36a0b19151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//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 <a href="mailto:unterstein@me.com">Johannes Unterstein</a>
 * @param <k>
 *            the class of the keys
 * @param <V>
 *            the class of the cached values
 */
public abstract aspect CacheAspect<V> {
    private HashMap<Object, V> cache;

    public abstract pointcut cachePoint(Object key);

    V around(Object key) : cachePoint(key) {
        if (this.cache == null) {
            this.cache = new HashMap<Object, V>();
        }
        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;
    }
}