K
- the type of the keys in this mapV
- the type of the values in this mappublic class DualTreeBidiMap<K,V> extends AbstractDualBidiMap<K,V> implements SortedBidiMap<K,V>, java.io.Serializable
BidiMap
that uses two TreeMap
instances.
The setValue() method on iterators will succeed only if the new value being set is not already in the bidimap.
When considering whether to use this class, the TreeBidiMap
class should
also be considered. It implements the interface using a dedicated design, and does
not store each object twice, which can save on memory use.
NOTE: From Commons Collections 3.1, all subclasses will use TreeMap
and the flawed createMap
method is ignored.
Modifier and Type | Class and Description |
---|---|
protected static class |
DualTreeBidiMap.BidiOrderedMapIterator<K,V>
Inner class MapIterator.
|
protected static class |
DualTreeBidiMap.ViewMap<K,V>
Internal sorted map view.
|
AbstractDualBidiMap.BidiMapIterator<K,V>, AbstractDualBidiMap.EntrySet<K,V>, AbstractDualBidiMap.EntrySetIterator<K,V>, AbstractDualBidiMap.KeySet<K>, AbstractDualBidiMap.KeySetIterator<K>, AbstractDualBidiMap.MapEntry<K,V>, AbstractDualBidiMap.Values<V>, AbstractDualBidiMap.ValuesIterator<V>, AbstractDualBidiMap.View<K,V,E>
Modifier and Type | Field and Description |
---|---|
private java.util.Comparator<? super K> |
comparator
The key comparator to use
|
private static long |
serialVersionUID
Ensure serialization compatibility
|
private java.util.Comparator<? super V> |
valueComparator
The value comparator to use
|
entrySet, inverseBidiMap, keySet, normalMap, reverseMap, values
Modifier | Constructor and Description |
---|---|
|
DualTreeBidiMap()
Creates an empty
DualTreeBidiMap |
|
DualTreeBidiMap(java.util.Comparator<? super K> keyComparator,
java.util.Comparator<? super V> valueComparator)
Constructs a
DualTreeBidiMap using the specified Comparator . |
|
DualTreeBidiMap(java.util.Map<? extends K,? extends V> map)
Constructs a
DualTreeBidiMap and copies the mappings from
specified Map . |
protected |
DualTreeBidiMap(java.util.Map<K,V> normalMap,
java.util.Map<V,K> reverseMap,
BidiMap<V,K> inverseBidiMap)
Constructs a
DualTreeBidiMap that decorates the specified maps. |
Modifier and Type | Method and Description |
---|---|
java.util.Comparator<? super K> |
comparator() |
protected DualTreeBidiMap<V,K> |
createBidiMap(java.util.Map<V,K> normalMap,
java.util.Map<K,V> reverseMap,
BidiMap<K,V> inverseMap)
Creates a new instance of this object.
|
K |
firstKey()
Gets the first key currently in this map.
|
java.util.SortedMap<K,V> |
headMap(K toKey) |
SortedBidiMap<V,K> |
inverseBidiMap()
Gets a view of this map where the keys and values are reversed.
|
OrderedBidiMap<V,K> |
inverseOrderedBidiMap() |
SortedBidiMap<V,K> |
inverseSortedBidiMap() |
K |
lastKey()
Gets the last key currently in this map.
|
OrderedMapIterator<K,V> |
mapIterator()
Obtains an ordered map iterator.
|
K |
nextKey(K key)
Gets the next key after the one specified.
|
K |
previousKey(K key)
Gets the previous key before the one specified.
|
private void |
readObject(java.io.ObjectInputStream in) |
java.util.SortedMap<K,V> |
subMap(K fromKey,
K toKey) |
java.util.SortedMap<K,V> |
tailMap(K fromKey) |
java.util.Comparator<? super V> |
valueComparator()
Get the comparator used for the values in the value-to-key map aspect.
|
private void |
writeObject(java.io.ObjectOutputStream out) |
clear, containsKey, containsValue, createEntrySetIterator, createKeySetIterator, createValuesIterator, entrySet, equals, get, getKey, hashCode, isEmpty, keySet, put, putAll, remove, removeValue, size, toString, values
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getKey, put, removeValue, values
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size
containsKey, containsValue, entrySet, get, isEmpty, keySet, remove, size
private static final long serialVersionUID
private final java.util.Comparator<? super K> comparator
private final java.util.Comparator<? super V> valueComparator
public DualTreeBidiMap()
DualTreeBidiMap
public DualTreeBidiMap(java.util.Map<? extends K,? extends V> map)
DualTreeBidiMap
and copies the mappings from
specified Map
.map
- the map whose mappings are to be placed in this mappublic DualTreeBidiMap(java.util.Comparator<? super K> keyComparator, java.util.Comparator<? super V> valueComparator)
DualTreeBidiMap
using the specified Comparator
.keyComparator
- the comparatorvalueComparator
- the values comparator to useprotected DualTreeBidiMap(java.util.Map<K,V> normalMap, java.util.Map<V,K> reverseMap, BidiMap<V,K> inverseBidiMap)
DualTreeBidiMap
that decorates the specified maps.normalMap
- the normal direction mapreverseMap
- the reverse direction mapinverseBidiMap
- the inverse BidiMapprotected DualTreeBidiMap<V,K> createBidiMap(java.util.Map<V,K> normalMap, java.util.Map<K,V> reverseMap, BidiMap<K,V> inverseMap)
createBidiMap
in class AbstractDualBidiMap<K,V>
normalMap
- the normal direction mapreverseMap
- the reverse direction mapinverseMap
- the inverse BidiMappublic java.util.Comparator<? super K> comparator()
public java.util.Comparator<? super V> valueComparator()
SortedBidiMap
valueComparator
in interface SortedBidiMap<K,V>
public K firstKey()
OrderedMap
public K lastKey()
OrderedMap
public K nextKey(K key)
OrderedMap
nextKey
in interface OrderedMap<K,V>
key
- the key to search for next frompublic K previousKey(K key)
OrderedMap
previousKey
in interface OrderedMap<K,V>
key
- the key to search for previous frompublic OrderedMapIterator<K,V> mapIterator()
This implementation copies the elements to an ArrayList in order to provide the forward/backward behaviour.
mapIterator
in interface IterableGet<K,V>
mapIterator
in interface OrderedMap<K,V>
mapIterator
in class AbstractDualBidiMap<K,V>
public SortedBidiMap<V,K> inverseSortedBidiMap()
public OrderedBidiMap<V,K> inverseOrderedBidiMap()
public SortedBidiMap<V,K> inverseBidiMap()
BidiMap
Changes to one map will be visible in the other and vice versa.
This enables both directions of the map to be accessed as a Map
.
Implementations should seek to avoid creating a new object every time this
method is called. See AbstractMap.values()
etc. Calling this
method on the inverse map should return the original.
inverseBidiMap
in interface BidiMap<K,V>
inverseBidiMap
in interface OrderedBidiMap<K,V>
inverseBidiMap
in interface SortedBidiMap<K,V>
inverseBidiMap
in class AbstractDualBidiMap<K,V>
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
java.io.IOException
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException