Class DualTreeBidiMap
- java.lang.Object
-
- org.apache.commons.collections.bidimap.AbstractDualBidiMap
-
- org.apache.commons.collections.bidimap.DualTreeBidiMap
-
- All Implemented Interfaces:
java.io.Serializable,java.util.Map,java.util.SortedMap,BidiMap,IterableMap,OrderedBidiMap,OrderedMap,SortedBidiMap
public class DualTreeBidiMap extends AbstractDualBidiMap implements SortedBidiMap, java.io.Serializable
Implementation ofBidiMapthat uses twoTreeMapinstances.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
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:
- Commons Collections 3.0
- Version:
- $Id: DualTreeBidiMap.java 646777 2008-04-10 12:33:15Z niallp $
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDualTreeBidiMap.BidiOrderedMapIteratorInner class MapIterator.protected static classDualTreeBidiMap.ViewMapInternal sorted map view.-
Nested classes/interfaces inherited from class org.apache.commons.collections.bidimap.AbstractDualBidiMap
AbstractDualBidiMap.BidiMapIterator, AbstractDualBidiMap.EntrySet, AbstractDualBidiMap.EntrySetIterator, AbstractDualBidiMap.KeySet, AbstractDualBidiMap.KeySetIterator, AbstractDualBidiMap.MapEntry, AbstractDualBidiMap.Values, AbstractDualBidiMap.ValuesIterator, AbstractDualBidiMap.View
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ComparatorcomparatorThe comparator to useprivate static longserialVersionUIDEnsure serialization compatibility-
Fields inherited from class org.apache.commons.collections.bidimap.AbstractDualBidiMap
entrySet, inverseBidiMap, keySet, maps, values
-
-
Constructor Summary
Constructors Modifier Constructor Description DualTreeBidiMap()Creates an emptyDualTreeBidiMapDualTreeBidiMap(java.util.Comparator comparator)Constructs aDualTreeBidiMapusing the specified Comparator.DualTreeBidiMap(java.util.Map map)Constructs aDualTreeBidiMapand copies the mappings from specifiedMap.protectedDualTreeBidiMap(java.util.Map normalMap, java.util.Map reverseMap, BidiMap inverseBidiMap)Constructs aDualTreeBidiMapthat decorates the specified maps.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Comparatorcomparator()protected BidiMapcreateBidiMap(java.util.Map normalMap, java.util.Map reverseMap, BidiMap inverseMap)Creates a new instance of this object.java.lang.ObjectfirstKey()Gets the first key currently in this map.java.util.SortedMapheadMap(java.lang.Object toKey)OrderedBidiMapinverseOrderedBidiMap()Gets a view of this map where the keys and values are reversed.SortedBidiMapinverseSortedBidiMap()Gets a view of this map where the keys and values are reversed.java.lang.ObjectlastKey()Gets the last key currently in this map.java.lang.ObjectnextKey(java.lang.Object key)Gets the next key after the one specified.OrderedMapIteratororderedMapIterator()Obtains an ordered map iterator.java.lang.ObjectpreviousKey(java.lang.Object key)Gets the previous key before the one specified.private voidreadObject(java.io.ObjectInputStream in)java.util.SortedMapsubMap(java.lang.Object fromKey, java.lang.Object toKey)java.util.SortedMaptailMap(java.lang.Object fromKey)private voidwriteObject(java.io.ObjectOutputStream out)-
Methods inherited from class org.apache.commons.collections.bidimap.AbstractDualBidiMap
clear, containsKey, containsValue, createEntrySetIterator, createKeySetIterator, createMap, createValuesIterator, entrySet, equals, get, getKey, hashCode, inverseBidiMap, isEmpty, keySet, mapIterator, put, putAll, remove, removeValue, size, toString, values
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.collections.BidiMap
getKey, mapIterator, put, removeValue
-
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size
-
Methods inherited from interface org.apache.commons.collections.SortedBidiMap
inverseBidiMap
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Ensure serialization compatibility- See Also:
- Constant Field Values
-
comparator
protected final java.util.Comparator comparator
The comparator to use
-
-
Constructor Detail
-
DualTreeBidiMap
public DualTreeBidiMap()
Creates an emptyDualTreeBidiMap
-
DualTreeBidiMap
public DualTreeBidiMap(java.util.Map map)
Constructs aDualTreeBidiMapand copies the mappings from specifiedMap.- Parameters:
map- the map whose mappings are to be placed in this map
-
DualTreeBidiMap
public DualTreeBidiMap(java.util.Comparator comparator)
Constructs aDualTreeBidiMapusing the specified Comparator.- Parameters:
comparator- the Comparator
-
DualTreeBidiMap
protected DualTreeBidiMap(java.util.Map normalMap, java.util.Map reverseMap, BidiMap inverseBidiMap)Constructs aDualTreeBidiMapthat decorates the specified maps.- Parameters:
normalMap- the normal direction mapreverseMap- the reverse direction mapinverseBidiMap- the inverse BidiMap
-
-
Method Detail
-
createBidiMap
protected BidiMap createBidiMap(java.util.Map normalMap, java.util.Map reverseMap, BidiMap inverseMap)
Creates a new instance of this object.- Specified by:
createBidiMapin classAbstractDualBidiMap- Parameters:
normalMap- the normal direction mapreverseMap- the reverse direction mapinverseMap- the inverse BidiMap- Returns:
- new bidi map
-
comparator
public java.util.Comparator comparator()
- Specified by:
comparatorin interfacejava.util.SortedMap
-
firstKey
public java.lang.Object firstKey()
Description copied from interface:OrderedMapGets the first key currently in this map.- Specified by:
firstKeyin interfaceOrderedMap- Specified by:
firstKeyin interfacejava.util.SortedMap- Returns:
- the first key currently in this map
-
lastKey
public java.lang.Object lastKey()
Description copied from interface:OrderedMapGets the last key currently in this map.- Specified by:
lastKeyin interfaceOrderedMap- Specified by:
lastKeyin interfacejava.util.SortedMap- Returns:
- the last key currently in this map
-
nextKey
public java.lang.Object nextKey(java.lang.Object key)
Description copied from interface:OrderedMapGets the next key after the one specified.- Specified by:
nextKeyin interfaceOrderedMap- Parameters:
key- the key to search for next from- Returns:
- the next key, null if no match or at end
-
previousKey
public java.lang.Object previousKey(java.lang.Object key)
Description copied from interface:OrderedMapGets the previous key before the one specified.- Specified by:
previousKeyin interfaceOrderedMap- Parameters:
key- the key to search for previous from- Returns:
- the previous key, null if no match or at start
-
orderedMapIterator
public OrderedMapIterator orderedMapIterator()
Obtains an ordered map iterator.This implementation copies the elements to an ArrayList in order to provide the forward/backward behaviour.
- Specified by:
orderedMapIteratorin interfaceOrderedMap- Returns:
- a new ordered map iterator
-
inverseSortedBidiMap
public SortedBidiMap inverseSortedBidiMap()
Description copied from interface:SortedBidiMapGets 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
SortedMap.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.The inverse map returned by
inverseBidiMap()should be the same object as returned by this method.- Specified by:
inverseSortedBidiMapin interfaceSortedBidiMap- Returns:
- an inverted bidirectional map
-
inverseOrderedBidiMap
public OrderedBidiMap inverseOrderedBidiMap()
Description copied from interface:OrderedBidiMapGets 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 equally.
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:
inverseOrderedBidiMapin interfaceOrderedBidiMap- Returns:
- an inverted bidirectional map
-
headMap
public java.util.SortedMap headMap(java.lang.Object toKey)
- Specified by:
headMapin interfacejava.util.SortedMap
-
tailMap
public java.util.SortedMap tailMap(java.lang.Object fromKey)
- Specified by:
tailMapin interfacejava.util.SortedMap
-
subMap
public java.util.SortedMap subMap(java.lang.Object fromKey, java.lang.Object toKey)- Specified by:
subMapin interfacejava.util.SortedMap
-
writeObject
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException- Throws:
java.io.IOException
-
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
-