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

Class AbstractBiMap

corpus/java/training/guava/collect/AbstractBiMap.java:50–452  ·  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

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected