View Javadoc
1   package de.fhdw.wtf.context.model.collections;
2   
3   import java.util.concurrent.ConcurrentHashMap;
4   
5   import de.fhdw.wtf.context.model.Anything;
6   
7   /**
8    * A class to represent Key-Value-Pairs of WTF-specific classes or interfaces.
9    * 
10   * @param <K>
11   *            K is a subtype of Anything and represents the Type of keys.
12   * @param <V>
13   *            V is a subtype of Anything and represents the Type of values.
14   */
15  public class TransientMap<K extends Anything, V extends Anything> extends MutableMap<K, V> {
16  	
17  	/**
18  	 * The underlying map.
19  	 */
20  	private final ConcurrentHashMap<K, V> internalMap;
21  	
22  	/**
23  	 * Creates a TransientMap.
24  	 */
25  	public TransientMap() {
26  		this.internalMap = new ConcurrentHashMap<>();
27  	}
28  	
29  	@Override
30  	public void put(final K key, final V value) {
31  		if (key == null || value == null) {
32  			throw new NullPointerException();
33  		}
34  		this.internalMap.put(key, value);
35  	}
36  	
37  	@Override
38  	public V get(final K key) {
39  		if (key == null) {
40  			throw new NullPointerException();
41  		}
42  		return this.internalMap.get(key);
43  	}
44  	
45  	@Override
46  	public V remove(final K key) {
47  		if (key == null) {
48  			throw new NullPointerException();
49  		}
50  		return this.internalMap.remove(key);
51  	}
52  	
53  	// @Override
54  	// public void clear() {
55  	// internalMap = new ConcurrentHashMap<K,V>();
56  	// }
57  }