|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.apache.commons.collections.bidimap.AbstractDualBidiMap
Abstract BidiMap implemented using two maps.
An implementation can be written simply by implementing the
createMap method.
DualHashBidiMap,
DualTreeBidiMap| Nested Class Summary | |
protected static class |
AbstractDualBidiMap.BidiMapIterator
Inner class MapIterator. |
protected static class |
AbstractDualBidiMap.EntrySet
Inner class EntrySet. |
protected static class |
AbstractDualBidiMap.EntrySetIterator
Inner class EntrySetIterator. |
protected static class |
AbstractDualBidiMap.KeySet
Inner class KeySet. |
protected static class |
AbstractDualBidiMap.KeySetIterator
Inner class KeySetIterator. |
protected static class |
AbstractDualBidiMap.MapEntry
Inner class MapEntry. |
protected static class |
AbstractDualBidiMap.Values
Inner class Values. |
protected static class |
AbstractDualBidiMap.ValuesIterator
Inner class ValuesIterator. |
protected static class |
AbstractDualBidiMap.View
Inner class View. |
| Nested classes inherited from class java.util.Map |
Map.Entry |
| Field Summary | |
protected Set |
entrySet
View of the entries. |
protected BidiMap |
inverseBidiMap
Inverse view of this map. |
protected Set |
keySet
View of the keys. |
protected Map[] |
maps
Delegate map array. |
protected Collection |
values
View of the values. |
| Constructor Summary | |
protected |
AbstractDualBidiMap()
Creates an empty map, initialised by createMap. |
protected |
AbstractDualBidiMap(Map normalMap,
Map reverseMap)
Creates an empty map using the two maps specified as storage. |
protected |
AbstractDualBidiMap(Map normalMap,
Map reverseMap,
BidiMap 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 BidiMap |
createBidiMap(Map normalMap,
Map reverseMap,
BidiMap inverseMap)
Creates a new instance of the subclass. |
protected Iterator |
createEntrySetIterator(Iterator iterator)
Creates an entry set iterator. |
protected Iterator |
createKeySetIterator(Iterator 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 |
createValuesIterator(Iterator iterator)
Creates a values iterator. |
Set |
entrySet()
Gets an entrySet view of the map. |
boolean |
equals(Object obj)
|
Object |
get(Object key)
|
Object |
getKey(Object value)
Gets the key that is currently mapped to the specified value. |
int |
hashCode()
|
BidiMap |
inverseBidiMap()
Gets a view of this map where the keys and values are reversed. |
boolean |
isEmpty()
|
Set |
keySet()
Gets a keySet view of the map. |
MapIterator |
mapIterator()
Obtains a MapIterator over the map. |
Object |
put(Object key,
Object value)
Puts the key-value pair into the map, replacing any previous pair. |
void |
putAll(Map map)
|
Object |
remove(Object key)
|
Object |
removeValue(Object value)
Removes the key-value pair that is currently mapped to the specified value (optional operation). |
int |
size()
|
String |
toString()
|
Collection |
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 final transient Map[] maps
protected transient BidiMap inverseBidiMap
protected transient Set keySet
protected transient Collection values
protected transient Set 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 normalMap,
Map reverseMap)
The two maps must be a matching pair, normal and reverse. They will typically both be empty.
Neither map is validated, so nulls may be passed in.
If you choose to do this then the subclass constructor must populate
the maps[] instance variable itself.
normalMap - the normal direction mapreverseMap - the reverse direction map
protected AbstractDualBidiMap(Map normalMap,
Map reverseMap,
BidiMap inverseBidiMap)
createBidiMap implementation.
normalMap - the normal direction mapreverseMap - the reverse direction mapinverseBidiMap - the inverse BidiMap| Method Detail |
protected Map createMap()
This design is deeply flawed and has been deprecated. It relied on subclass data being used during a superclass constructor.
protected abstract BidiMap createBidiMap(Map normalMap,
Map reverseMap,
BidiMap inverseMap)
normalMap - the normal direction mapreverseMap - the reverse direction mapinverseMap - this map, which is the inverse in the new map
public Object get(Object key)
get in interface Mappublic int size()
size in interface Mappublic boolean isEmpty()
isEmpty in interface Mappublic boolean containsKey(Object key)
containsKey in interface Mappublic boolean equals(Object obj)
equals in interface Mappublic int hashCode()
hashCode in interface Mappublic String toString()
public Object put(Object key,
Object value)
BidiMapWhen adding a key-value pair, the value may already exist in the map against a different key. That mapping is removed, to ensure that the value only occurs once in the inverse map.
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 BidiMapkey - the key to storevalue - the value to store
public void putAll(Map map)
putAll in interface Mappublic Object remove(Object key)
remove in interface Mappublic void clear()
clear in interface Mappublic boolean containsValue(Object value)
containsValue in interface Mappublic MapIterator 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 BidiMappublic Object getKey(Object value)
BidiMap
If the value is not contained in the map, null is returned.
Implementations should seek to make this method perform equally as well
as get(Object).
getKey in interface BidiMapvalue - the value to find the key for
null if not foundpublic Object removeValue(Object value)
BidiMap
If the value is not contained in the map, null is returned.
Implementations should seek to make this method perform equally as well
as remove(Object).
removeValue in interface BidiMapvalue - the value to find the key-value pair for
null if nothing removedpublic BidiMap 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 BidiMappublic Set keySet()
keySet in interface Mapprotected Iterator createKeySetIterator(Iterator iterator)
iterator - the iterator to decorate
public Collection values()
values in interface Mapprotected Iterator createValuesIterator(Iterator iterator)
iterator - the iterator to decorate
public Set entrySet()
The Map Entry setValue() method 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).
entrySet in interface Mapprotected Iterator createEntrySetIterator(Iterator iterator)
iterator - the iterator to decorate
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||