Comparable interface.
This class guarantees that the map will be in both ascending key order and ascending value order, sorted according to the natural order for the key's and value's classes.
This Map is intended for applications that need to be able to look up a key-value pairing by either key or value, and need to do so with equal efficiency.
While that goal could be accomplished by taking a pair of TreeMaps
and redirecting requests to the appropriate TreeMap (e.g.,
containsKey would be directed to the TreeMap that maps values to
keys, containsValue would be directed to the TreeMap that maps keys
to values), there are problems with that implementation.
If the data contained in the TreeMaps is large, the cost of redundant
storage becomes significant. The DualTreeBidiMap and
DualHashBidiMap implementations use this approach.
This solution keeps minimizes the data storage by holding data only once.
The red-black algorithm is based on java., but has been modified
to simultaneously map a tree node by key and by value. This doubles the
cost of put operations (but so does using two TreeMaps), and nearly doubles
the cost of remove operations (there is a savings in that the lookup of the
node to be removed only has to be performed once). And since only one node
contains the key and value, storage is significantly less than that
required by two TreeMaps.
The Map.Entry instances returned by the appropriate methods will not allow setValue() and will throw an UnsupportedOperationException on attempts to call that method.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static enum | |
| pack-priv class | TreeBidiMap.EntryView
A view of this map. |
| pack-priv class | TreeBidiMap.Inverse
The inverse map implementation. |
| pack-priv class | TreeBidiMap.InverseEntryView
A view of this map. |
| pack-priv class | TreeBidiMap.InverseViewMapEntryIterator
An iterator over the inverse map entries. |
| pack-priv class | TreeBidiMap.InverseViewMapIterator
An iterator over the map. |
| pack-priv class | |
| pack-priv static class | |
| pack-priv class | |
| pack-priv abstract class | |
| pack-priv abstract class | TreeBidiMap.ViewIterator
An iterator over the map. |
| pack-priv class | TreeBidiMap.ViewMapEntryIterator
An iterator over the map entries. |
| pack-priv class | TreeBidiMap.ViewMapIterator
An iterator over the map. |
| Modifier and Type | Field and Description |
|---|---|
| private transient Set | |
| private transient TreeBidiMap | |
| private transient Set | |
| private transient int | |
| private transient int | |
| private transient TreeBidiMap. | |
| private static final long | |
| private transient Set |
| Access | Constructor and Description |
|---|---|
| public | |
| public | TreeBidiMap(final Map<? extends K, ? extends V>
the map to copy map)Constructs a new TreeBidiMap by copying an existing Map. |
| Modifier and Type | Method and Description |
|---|---|
| private static void | |
| private static void | checkKeyAndValue(final Object
the key to be checked key, final Object the value to be checked value)check a key and a value for validity (non-null and implements Comparable) |
| private static void | checkNonNullComparable(final Object
the object being checked o, final TreeBidiMap.either dataElementDataElement#KEY key}
or the value.check if an object is fit to be proper input ... |
| private static void | checkValue(final Object
the value to be checked value)check a value for validity (non-null and implements Comparable) |
| public void | clear()
Implements java. |
| private static <T extends Comparable | Returns: negative value if o1 < o2; 0 if o1 == o2; positive value if o1 > o2the first object o1, final T the second object o2)Compare two objects |
| public boolean | Returns: true if this map contains a mapping for the specified keykey whose presence in this map is to be tested key)Implements java. |
| public boolean | Returns: true if this map contains a mapping for the specified valuevalue whose presence in this map is to be tested value)Implements java. |
| private void | copyColor(final TreeBidiMap.
the node whose color we're copying; may be null from,the node whose color we're changing; may be null to,either dataElementDataElement#KEY key}
or the value.copy the color from one node to another, dealing with the fact that one or both nodes may, in fact, be null |
| private boolean | Returns: true if equalthe object to compare to obj, final TreeBidiMap.either dataElementDataElement#KEY key}
or the value.Compares for equals as per the API. |
| private int | Returns: the hash code value for this mapeither dataElementDataElement#KEY key}
or the value.Gets the hash code value for this map as per the API. |
| private void | doPut(final K
the key, always the main map key key, final V the value, always the main map value value)Put logic. |
| private void | doRedBlackDelete(final TreeBidiMap.
the node to be deleted deletedNodecomplicated red-black delete stuff. |
| private void | doRedBlackDeleteFixup(final TreeBidiMap.
the node being replaced replacementNode,the KEY or VALUE int dataElementcomplicated red-black delete stuff. |
| private void | doRedBlackInsert(final TreeBidiMap.
the node to be inserted insertedNode,the KEY or VALUE int dataElementcomplicated red-black insert stuff. |
| private V | |
| private K | |
| private String | Returns: the string form of this mapeither dataElementDataElement#KEY key}
or the value.Gets the string form of this map as per AbstractMap. |
| public Set | Returns: a set view of the values contained in this map.Implements java. |
| public boolean | Returns: true if equalthe object to compare to obj)Overrides java. Implements java. |
| public K | Returns: the first (lowest) key currently in this sorted mapImplements org. |
| public V | Returns: the value to which this map maps the specified key, or null if the map contains no mapping for this keykey whose associated value is to be returned key)Implements java. |
| private TreeBidiMap. | getGrandParent(final TreeBidiMap.
the node (may be null) in question node,either dataElementDataElement#KEY key}
or the value.get a node's grandparent. |
| public K | Returns: the key to which this map maps the specified value, or null if the map contains no mapping for this value.value whose associated key is to be returned. value)Implements org. |
| private TreeBidiMap. | getLeftChild(final TreeBidiMap.
the node (may be null) in question node,either dataElementDataElement#KEY key}
or the value.get a node's left child. |
| private MapIterator | |
| private TreeBidiMap. | getParent(final TreeBidiMap.
the node (may be null) in question node,either dataElementDataElement#KEY key}
or the value.get a node's parent. |
| private TreeBidiMap. | getRightChild(final TreeBidiMap.
the node (may be null) in question node,either dataElementDataElement#KEY key}
or the value.get a node's right child. |
| private TreeBidiMap. | Returns: the greatest node, from the specified nodethe node from which we will start searching node,either dataElementDataElement#KEY key}
or the value.Find the greatest node from a given node. |
| private void | |
| public int | Returns: the hash code value for this mapOverrides java. Implements java. |
| private void | |
| public OrderedBidiMap | Returns: the inverse mapImplements org. |
| private static boolean | isBlack(final TreeBidiMap.
the node (may be null) in question node,either dataElementDataElement#KEY key}
or the value.is the specified black red? |
| public boolean | Returns: true if the map is emptyImplements java. |
| private static boolean | isRed(final TreeBidiMap.
the node (may be null) in question node,either dataElementDataElement#KEY key}
or the value.is the specified node red? |
| public Set | Returns: a set view of the keys contained in this map.Implements java. |
| public K | Returns: the last (highest) key currently in this sorted mapImplements org. |
| private TreeBidiMap. | Returns: the smallest node, from the specified node, in the specified mappingthe node from which we will start searching node,either dataElementDataElement#KEY key}
or the value.Find the least node from a given node. |
| private <T extends Comparable | Returns: the desired Node, or null if there is no mapping of the specified datathe key or value to be looked up data, final TreeBidiMap.either dataElementDataElement#KEY key}
or the value.do the actual lookup of a piece of data |
| private TreeBidiMap. | |
| private TreeBidiMap. | |
| private static void | makeBlack(final TreeBidiMap.
the node (may be null) in question node,either dataElementDataElement#KEY key}
or the value.force a node (if it exists) black |
| private static void | makeRed(final TreeBidiMap.
the node (may be null) in question node,either dataElementDataElement#KEY key}
or the value.force a node (if it exists) red |
| public OrderedMapIterator | mapIterator()
Implements org. OrderedMapIterator over the map.
|
| private void | modify()
increment the modification count -- used to check for concurrent modification of the map through the map and through an Iterator from one of its Set or Collection views |
| private TreeBidiMap. | Returns: the specified nodethe node to be searched from node,either dataElementDataElement#KEY key}
or the value.get the next larger node from the specified node |
| public K | Returns: the next key, null if no match or at endthe key to search for next from key)Implements org. |
| private TreeBidiMap. | Returns: the specified nodethe node to be searched from node,either dataElementDataElement#KEY key}
or the value.get the next larger node from the specified node |
| public K | Returns: the previous key, null if no match or at startthe key to search for previous from key)Implements org. |
| public V | Returns: the previous value for the keykey with which the specified value is to be associated key, final V value to be associated with the specified key value)Implements org. |
| public void | putAll(final Map<? extends K, ? extends V>
the map to copy from map)Implements java. |
| private void | |
| public V | Returns: previous value associated with specified key, or null if there was no mapping for key.key whose mapping is to be removed from the map. key)Implements java. |
| public K | Returns: previous key associated with specified value, or null if there was no mapping for value.value whose mapping is to be removed from the map value)Implements org. |
| private void | rotateLeft(final TreeBidiMap.
the node to be rotated node,either dataElementDataElement#KEY key}
or the value.do a rotate left. |
| private void | rotateRight(final TreeBidiMap.
the node to be rotated node,either dataElementDataElement#KEY key}
or the value.do a rotate right. |
| private void | |
| public int | Returns: the number of key-value mappings in this mapImplements java. |
| private void | swapPosition(final TreeBidiMap.
one node x,another node y,the KEY or VALUE int dataElementswap two nodes (except for their content), taking care of special cases where one is the other's parent ... |
| public String | Returns: a standard format string version of the mapOverrides java. |
| public Set | Returns: a set view of the values contained in this map.Implements org. |
| private void | writeObject(final ObjectOutputStream
the output stream stream)Writes the content to the stream for serialization. |