View Javadoc
1   /*
2    * Copyright 2016 The Lannister Project
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.anyflow.lannister.cluster;
17  
18  import com.google.common.collect.Maps;
19  
20  public class NativeSetValueMap<K, V> implements Map<K, Set<V>> {
21  
22  	private final java.util.Map<K, Set<V>> engine;
23  
24  	public NativeSetValueMap(String name) {
25  		engine = Maps.newHashMap();
26  	}
27  
28  	@Override
29  	public void put(K key, Set<V> value) {
30  		Set<V> prev = engine.put(key, value);
31  		if (prev != null) {
32  			prev.dispose();
33  		}
34  	}
35  
36  	@Override
37  	public Set<V> get(K key) {
38  		return engine.get(key);
39  	}
40  
41  	@Override
42  	public Set<V> remove(K key) {
43  		return engine.remove(key);
44  	}
45  
46  	@Override
47  	public int size() {
48  		return engine.size();
49  	}
50  
51  	@Override
52  	public void dispose() {
53  		// DO NOTHING
54  	}
55  
56  	@Override
57  	public boolean containsKey(K key) {
58  		return engine.containsKey(key);
59  	}
60  
61  	@Override
62  	public java.util.Set<K> keySet() {
63  		return engine.keySet();
64  	}
65  }