MCPcopy Index your code
hub / github.com/antlr/codebuff / AbstractBiMap

Class AbstractBiMap

output/java_guava/1.4.16/AbstractBiMap.java:49–464  ·  view source on GitHub ↗

A general-purpose bimap implementation using any two backing Map instances. Note that this class contains equals() calls that keep it from supporting IdentityHashMap backing maps. @author Kevin Bourrillion @author Mike Bostock

Source from the content-addressed store, hash-verified

47
48
49@GwtCompatible(emulated = true)
50abstract class AbstractBiMap<K, V> extends ForwardingMap<K, V> implements BiMap<K, V>, Serializable {
51 private transient Map<K, V> delegate;
52 transient AbstractBiMap<V, K> inverse;
53
54 /** Package-private constructor for creating a map-backed bimap. */
55
56 AbstractBiMap(Map<K, V> forward, Map<V, K> backward) {
57 setDelegates(forward, backward);
58 }
59
60 /** Private constructor for inverse bimap. */
61
62 private AbstractBiMap(Map<K, V> backward, AbstractBiMap<V, K> forward) {
63 delegate = backward;
64 inverse = forward;
65 }
66
67 @Override
68 protected Map<K, V> delegate() {
69 return delegate;
70 }
71
72 /**
73 * Returns its input, or throws an exception if this is not a valid key.
74 */
75
76 @CanIgnoreReturnValue
77 K checkKey(@Nullable K key) {
78 return key;
79 }
80
81 /**
82 * Returns its input, or throws an exception if this is not a valid value.
83 */
84
85 @CanIgnoreReturnValue
86 V checkValue(@Nullable V value) {
87 return value;
88 }
89
90 /**
91 * Specifies the delegate maps going in each direction. Called by the
92 * constructor and by subclasses during deserialization.
93 */
94
95
96 void setDelegates(Map<K, V> forward, Map<V, K> backward) {
97 checkState(delegate == null);
98 checkState(inverse == null);
99 checkArgument(forward.isEmpty());
100 checkArgument(backward.isEmpty());
101 checkArgument(forward != backward);
102 delegate = forward;
103 inverse = new Inverse<V, K>(backward, this);
104 }
105
106

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected