Class DualTreeBidiMap<K,V>
- java.lang.Object
-
- org.apache.commons.collections4.bidimap.AbstractDualBidiMap<K,V>
-
- org.apache.commons.collections4.bidimap.DualTreeBidiMap<K,V>
-
- Type Parameters:
K- the type of the keys in this mapV- the type of the values in this map
- All Implemented Interfaces:
java.io.Serializable,java.util.Map<K,V>,java.util.SortedMap<K,V>,BidiMap<K,V>,Get<K,V>,IterableGet<K,V>,IterableMap<K,V>,OrderedBidiMap<K,V>,OrderedMap<K,V>,Put<K,V>,SortedBidiMap<K,V>
public class DualTreeBidiMap<K,V> extends AbstractDualBidiMap<K,V> implements SortedBidiMap<K,V>, java.io.Serializable
ImplementsBidiMapwith twoTreeMapinstances.The setValue() method on iterators will succeed only if the new value being set is not already in the bidi map.
When considering whether to use this class, the
TreeBidiMapclass 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
TreeMapand the flawedcreateMapmethod is ignored.- Since:
- 3.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DualTreeBidiMap()Creates an emptyDualTreeBidiMap.DualTreeBidiMap(java.util.Comparator<? super K> keyComparator, java.util.Comparator<? super V> valueComparator)Constructs aDualTreeBidiMapusing the specifiedComparator.DualTreeBidiMap(java.util.Map<? extends K,? extends V> map)Constructs aDualTreeBidiMapand copies the mappings from specifiedMap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Comparator<? super K>comparator()KfirstKey()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()Defaults toinverseBidiMap().SortedBidiMap<V,K>inverseSortedBidiMap()Defaults toinverseBidiMap().KlastKey()Gets the last key currently in this map.OrderedMapIterator<K,V>mapIterator()Obtains an ordered map iterator.KnextKey(K key)Gets the next key after the one specified.KpreviousKey(K key)Gets the previous key before the one specified.java.util.SortedMap<K,V>subMap(K fromKey, K toKey)java.util.SortedMap<K,V>tailMap(K fromKey)java.util.Comparator<? super V>valueComparator()Gets the comparator used for the values in the value-to-key map aspect.-
Methods inherited from class org.apache.commons.collections4.bidimap.AbstractDualBidiMap
clear, containsKey, containsValue, entrySet, equals, get, getKey, hashCode, isEmpty, keySet, put, putAll, remove, removeValue, size, toString, values
-
Methods inherited from interface org.apache.commons.collections4.BidiMap
getKey, put, removeValue, values
-
Methods inherited from interface org.apache.commons.collections4.Get
containsKey, containsValue, entrySet, get, isEmpty, keySet, remove, size, values
-
-
-
-
Constructor Detail
-
DualTreeBidiMap
public DualTreeBidiMap()
Creates an emptyDualTreeBidiMap.
-
DualTreeBidiMap
public DualTreeBidiMap(java.util.Comparator<? super K> keyComparator, java.util.Comparator<? super V> valueComparator)
Constructs aDualTreeBidiMapusing the specifiedComparator.- Parameters:
keyComparator- the comparatorvalueComparator- the values comparator to use
-
DualTreeBidiMap
public DualTreeBidiMap(java.util.Map<? extends K,? extends V> map)
Constructs aDualTreeBidiMapand copies the mappings from specifiedMap.- Parameters:
map- the map whose mappings are to be placed in this map
-
-
Method Detail
-
comparator
public java.util.Comparator<? super K> comparator()
-
firstKey
public K firstKey()
Description copied from interface:OrderedMapGets the first key currently in this map.
-
inverseBidiMap
public SortedBidiMap<V,K> inverseBidiMap()
Description copied from interface:BidiMapGets a view of this map where the keys and values are reversed.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.- Specified by:
inverseBidiMapin interfaceBidiMap<K,V>- Specified by:
inverseBidiMapin interfaceOrderedBidiMap<K,V>- Specified by:
inverseBidiMapin interfaceSortedBidiMap<K,V>- Overrides:
inverseBidiMapin classAbstractDualBidiMap<K,V>- Returns:
- an inverted bidirectional map
-
inverseOrderedBidiMap
public OrderedBidiMap<V,K> inverseOrderedBidiMap()
Defaults toinverseBidiMap().- Returns:
- Defaults to
inverseBidiMap().
-
inverseSortedBidiMap
public SortedBidiMap<V,K> inverseSortedBidiMap()
Defaults toinverseBidiMap().- Returns:
- Defaults to
inverseBidiMap().
-
lastKey
public K lastKey()
Description copied from interface:OrderedMapGets the last key currently in this map.
-
mapIterator
public OrderedMapIterator<K,V> mapIterator()
Obtains an ordered map iterator.This implementation copies the elements to an ArrayList in order to provide the forward/backward behavior.
- Specified by:
mapIteratorin interfaceIterableGet<K,V>- Specified by:
mapIteratorin interfaceOrderedMap<K,V>- Overrides:
mapIteratorin classAbstractDualBidiMap<K,V>- Returns:
- a new ordered map iterator
-
nextKey
public K nextKey(K key)
Description copied from interface:OrderedMapGets the next key after the one specified.- Specified by:
nextKeyin interfaceOrderedMap<K,V>- Parameters:
key- the key to search for next from- Returns:
- the next key, null if no match or at end
-
previousKey
public K previousKey(K key)
Description copied from interface:OrderedMapGets the previous key before the one specified.- Specified by:
previousKeyin interfaceOrderedMap<K,V>- Parameters:
key- the key to search for previous from- Returns:
- the previous key, null if no match or at start
-
valueComparator
public java.util.Comparator<? super V> valueComparator()
Description copied from interface:SortedBidiMapGets the comparator used for the values in the value-to-key map aspect.- Specified by:
valueComparatorin interfaceSortedBidiMap<K,V>- Returns:
- Comparator<? super V>
-
-