Skip to main content
summaryrefslogtreecommitdiffstats
blob: cfd0234242c8f6469b3bc8963ae9be72f0a2d8c9 (plain) (blame)
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
package org.eclipse.xtend.backend.util;

import java.util.HashMap;
import java.util.Map;


/**
 * 
 * @author Arno Haase (http://www.haase-consulting.com)
 */
public abstract class DoubleKeyCache<K1, K2, V> {
    private final Map<Pair<K1, K2>, V> _cache = new HashMap<Pair <K1, K2>, V>();
    
    public V get (K1 key1, K2 key2) {
        final Pair<K1, K2> key = new Pair<K1, K2> (key1, key2);
        
        if (_cache.containsKey (key))
            return _cache.get (key);
        
        final V result = create (key1, key2);
        _cache.put (key, result);
        return result;
    }

    protected abstract V create (K1 key1, K2 key2);
    
    public Map<Pair<K1, K2>, V> getMap () {
        return _cache;
    }
}

Back to the top