Initial opendaylight infrastructure commit!!
[controller.git] / third-party / net.sf.jung2 / src / main / java / edu / uci / ics / jung / algorithms / util / ConstantMap.java
1 /*
2 * Copyright (c) 2003, the JUNG Project and the Regents of the University 
3 * of California
4 * All rights reserved.
5 *
6 * This software is open-source under the BSD license; see either
7 * "license.txt" or
8 * http://jung.sourceforge.net/license.txt for a description.
9 */
10
11 package edu.uci.ics.jung.algorithms.util;
12
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.Map;
16 import java.util.Set;
17
18 /**
19  * An implementation of <code>Map</code> that returns the constructor-supplied
20  * value for any input.
21  *
22  * @param <K> the key type
23  * @param <V> the value type
24  */
25 public class ConstantMap<K,V> implements Map<K,V> {
26
27         private Map<K,V> delegate;
28         
29         /**
30          * Creates an instance whose {@code get} method always returns {@code value}.
31          */
32         public ConstantMap(V value) {
33                 delegate = Collections.<K,V>unmodifiableMap(Collections.<K,V>singletonMap(null, value));
34         }
35
36         public V get(Object key) {
37                 return delegate.get(null);
38         }
39         
40         public void clear() {
41                 delegate.clear();
42         }
43         
44         public boolean containsKey(Object key) {
45                 return true;
46         }
47         
48         public boolean containsValue(Object value) {
49                 return delegate.containsValue(value);
50         }
51         
52         public Set<Entry<K, V>> entrySet() {
53                 return delegate.entrySet();
54         }
55         
56         @Override
57         public boolean equals(Object o) {
58                 return delegate.equals(o);
59         }
60         
61         @Override
62         public int hashCode() {
63                 return delegate.hashCode();
64         }
65         
66         public boolean isEmpty() {
67                 return delegate.isEmpty();
68         }
69         
70         public Set<K> keySet() {
71                 return delegate.keySet();
72         }
73         
74         public V put(K key, V value) {
75                 return delegate.put(key, value);
76         }
77         
78         public void putAll(Map<? extends K, ? extends V> t) {
79                 delegate.putAll(t);
80         }
81         
82         public V remove(Object key) {
83                 return delegate.remove(key);
84         }
85         
86         public int size() {
87                 return delegate.size();
88         }
89         
90         public Collection<V> values() {
91                 return delegate.values();
92         }
93 }