|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.collections.bidimap.AbstractDualBidiMap<K,V>
public abstract class AbstractDualBidiMap<K,V>
Abstract BidiMap
implemented using two maps.
createMap
method.
DualHashBidiMap
,
DualTreeBidiMap
Nested Class Summary | |
---|---|
protected static class |
AbstractDualBidiMap.BidiMapIterator<K,V>
Inner class MapIterator. |
protected static class |
AbstractDualBidiMap.EntrySet<K,V>
Inner class EntrySet. |
protected static class |
AbstractDualBidiMap.EntrySetIterator<K,V>
Inner class EntrySetIterator. |
protected static class |
AbstractDualBidiMap.KeySet<K,V>
Inner class KeySet. |
protected static class |
AbstractDualBidiMap.KeySetIterator<K,V>
Inner class KeySetIterator. |
protected static class |
AbstractDualBidiMap.MapEntry<K,V>
Inner class MapEntry. |
protected static class |
AbstractDualBidiMap.Values<K,V>
Inner class Values. |
protected static class |
AbstractDualBidiMap.ValuesIterator<K,V>
Inner class ValuesIterator. |
protected static class |
AbstractDualBidiMap.View<K,V,E>
Inner class View. |
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Field Summary | |
---|---|
protected Set<Map.Entry<K,V>> |
entrySet
View of the entries. |
protected Map<K,V> |
forwardMap
Delegate maps. |
protected BidiMap<V,K> |
inverseBidiMap
Inverse view of this map. |
protected Map<V,K> |
inverseMap
|
protected Set<K> |
keySet
View of the keys. |
protected Collection<V> |
values
View of the values. |
Constructor Summary | |
---|---|
protected |
AbstractDualBidiMap()
Deprecated. should not be used. |
protected |
AbstractDualBidiMap(Map<K,V> normalMap,
Map<V,K> reverseMap)
Creates an empty map using the two maps specified as storage. |
protected |
AbstractDualBidiMap(Map<K,V> normalMap,
Map<V,K> reverseMap,
BidiMap<V,K> inverseBidiMap)
Constructs a map that decorates the specified maps, used by the subclass createBidiMap implementation. |
Method Summary | ||
---|---|---|
void |
clear()
|
|
boolean |
containsKey(Object key)
|
|
boolean |
containsValue(Object value)
|
|
protected abstract
|
createBidiMap(Map<K,V> normalMap,
Map<V,K> reverseMap,
BidiMap<V,K> inverseMap)
Creates a new instance of the subclass. |
|
protected Iterator<Map.Entry<K,V>> |
createEntrySetIterator(Iterator<Map.Entry<K,V>> iterator)
Creates an entry set iterator. |
|
protected Iterator<K> |
createKeySetIterator(Iterator<K> iterator)
Creates a key set iterator. |
|
protected Map |
createMap()
Deprecated. For constructors, use the new two map constructor. For deserialization, populate the maps array directly in readObject. |
|
protected Iterator<V> |
createValuesIterator(Iterator<V> iterator)
Creates a values iterator. |
|
Set<Map.Entry<K,V>> |
entrySet()
Gets an entrySet view of the map. |
|
boolean |
equals(Object obj)
|
|
V |
get(Object key)
|
|
K |
getKey(V value)
Gets the key that is currently mapped to the specified value. |
|
int |
hashCode()
|
|
BidiMap<V,K> |
inverseBidiMap()
Gets a view of this map where the keys and values are reversed. |
|
boolean |
isEmpty()
|
|
Set<K> |
keySet()
Gets a keySet view of the map. |
|
MapIterator<K,V> |
mapIterator()
Obtains a MapIterator over the map. |
|
V |
put(K key,
V value)
Puts the key-value pair into the map, replacing any previous pair. |
|
void |
putAll(Map<? extends K,? extends V> map)
|
|
V |
remove(Object key)
|
|
K |
removeValue(V value)
Removes the key-value pair that is currently mapped to the specified value (optional operation). |
|
int |
size()
|
|
String |
toString()
|
|
Collection<V> |
values()
Gets a values view of the map. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected transient Map<K,V> forwardMap
protected transient Map<V,K> inverseMap
protected transient BidiMap<V,K> inverseBidiMap
protected transient Set<K> keySet
protected transient Collection<V> values
protected transient Set<Map.Entry<K,V>> entrySet
Constructor Detail |
---|
protected AbstractDualBidiMap()
createMap
.
This constructor remains in place for deserialization.
All other usage is deprecated in favour of
AbstractDualBidiMap(Map, Map)
.
protected AbstractDualBidiMap(Map<K,V> normalMap, Map<V,K> reverseMap)
maps[]
instance variable itself.
normalMap
- the normal direction mapreverseMap
- the reverse direction mapprotected AbstractDualBidiMap(Map<K,V> normalMap, Map<V,K> reverseMap, BidiMap<V,K> inverseBidiMap)
createBidiMap
implementation.
normalMap
- the normal direction mapreverseMap
- the reverse direction mapinverseBidiMap
- the inverse BidiMapMethod Detail |
---|
protected Map createMap()
protected abstract <K,V> BidiMap<K,V> createBidiMap(Map<K,V> normalMap, Map<V,K> reverseMap, BidiMap<V,K> inverseMap)
normalMap
- the normal direction mapreverseMap
- the reverse direction mapinverseMap
- this map, which is the inverse in the new map
public V get(Object key)
get
in interface Map<K,V>
public int size()
size
in interface Map<K,V>
public boolean isEmpty()
isEmpty
in interface Map<K,V>
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
public boolean equals(Object obj)
equals
in interface Map<K,V>
equals
in class Object
public int hashCode()
hashCode
in interface Map<K,V>
hashCode
in class Object
public String toString()
toString
in class Object
public V put(K key, V value)
BidiMap
BidiMap map1 = new DualHashBidiMap(); map.put("A","B"); // contains A mapped to B, as per Map map.put("A","C"); // contains A mapped to C, as per Map BidiMap map2 = new DualHashBidiMap(); map.put("A","B"); // contains A mapped to B, as per Map map.put("C","B"); // contains C mapped to B, key A is removed
put
in interface Map<K,V>
put
in interface BidiMap<K,V>
key
- the key to storevalue
- the value to store
public void putAll(Map<? extends K,? extends V> map)
putAll
in interface Map<K,V>
public V remove(Object key)
remove
in interface Map<K,V>
public void clear()
clear
in interface Map<K,V>
public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
public MapIterator<K,V> mapIterator()
MapIterator
over the map.
The iterator implements ResetableMapIterator
.
This implementation relies on the entrySet iterator.
The setValue() methods only allow a new value to be set.
If the value being set is already in the map, an IllegalArgumentException
is thrown (as setValue cannot change the size of the map).
mapIterator
in interface BidiMap<K,V>
mapIterator
in interface IterableMap<K,V>
public K getKey(V value)
BidiMap
null
is returned.
Implementations should seek to make this method perform equally as well
as get(Object)
.
getKey
in interface BidiMap<K,V>
value
- the value to find the key for
null
if not foundpublic K removeValue(V value)
BidiMap
null
is returned.
Implementations should seek to make this method perform equally as well
as remove(Object)
.
removeValue
in interface BidiMap<K,V>
value
- the value to find the key-value pair for
null
if nothing removedpublic BidiMap<V,K> inverseBidiMap()
BidiMap
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>
public Set<K> keySet()
keySet
in interface Map<K,V>
protected Iterator<K> createKeySetIterator(Iterator<K> iterator)
iterator
- the iterator to decorate
public Collection<V> values()
values
in interface Map<K,V>
protected Iterator<V> createValuesIterator(Iterator<V> iterator)
iterator
- the iterator to decorate
public Set<Map.Entry<K,V>> entrySet()
entrySet
in interface Map<K,V>
protected Iterator<Map.Entry<K,V>> createEntrySetIterator(Iterator<Map.Entry<K,V>> iterator)
iterator
- the iterator to decorate
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |