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

Class AbstractBiMap

output/java_guava/1.4.13/AbstractBiMap.java:49–457  ·  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 void setDelegates(Map<K, V> forward, Map<V, K> backward) {
96 checkState(delegate == null);
97 checkState(inverse == null);
98 checkArgument(forward.isEmpty());
99 checkArgument(backward.isEmpty());
100 checkArgument(forward != backward);
101 delegate = forward;
102 inverse = new Inverse<V, K>(backward, this);
103 }
104
105 void setInverse(AbstractBiMap<V, K> inverse) {
106 this.inverse = inverse;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected