Class UnmodifiableBidiMap
- java.lang.Object
-
- org.apache.commons.collections.map.AbstractMapDecorator
-
- org.apache.commons.collections.bidimap.AbstractBidiMapDecorator
-
- org.apache.commons.collections.bidimap.UnmodifiableBidiMap
-
- All Implemented Interfaces:
java.util.Map,BidiMap,IterableMap,Unmodifiable
public final class UnmodifiableBidiMap extends AbstractBidiMapDecorator implements Unmodifiable
Decorates anotherBidiMapto ensure it can't be altered.- Since:
- Commons Collections 3.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()static BidiMapdecorate(BidiMap map)Factory method to create an unmodifiable map.java.util.SetentrySet()BidiMapinverseBidiMap()Gets a view of this map where the keys and values are reversed.java.util.SetkeySet()MapIteratormapIterator()Obtains aMapIteratorover the map.java.lang.Objectput(java.lang.Object key, java.lang.Object value)Puts the key-value pair into the map, replacing any previous pair.voidputAll(java.util.Map mapToCopy)java.lang.Objectremove(java.lang.Object key)java.lang.ObjectremoveValue(java.lang.Object value)Removes the key-value pair that is currently mapped to the specified value (optional operation).java.util.Collectionvalues()-
Methods inherited from class org.apache.commons.collections.bidimap.AbstractBidiMapDecorator
getKey
-
Methods inherited from class org.apache.commons.collections.map.AbstractMapDecorator
containsKey, containsValue, equals, get, hashCode, isEmpty, size, toString
-
-
-
-
Method Detail
-
decorate
public static BidiMap decorate(BidiMap map)
Factory method to create an unmodifiable map.If the map passed in is already unmodifiable, it is returned.
- Parameters:
map- the map to decorate, must not be null- Returns:
- an unmodifiable BidiMap
- Throws:
java.lang.IllegalArgumentException- if map is null
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Map- Overrides:
clearin classAbstractMapDecorator
-
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)Description copied from interface:BidiMapPuts the key-value pair into the map, replacing any previous pair.When 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- Specified by:
putin interfaceBidiMap- Specified by:
putin interfacejava.util.Map- Overrides:
putin classAbstractMapDecorator- Parameters:
key- the key to storevalue- the value to store- Returns:
- the previous value mapped to this key
-
putAll
public void putAll(java.util.Map mapToCopy)
- Specified by:
putAllin interfacejava.util.Map- Overrides:
putAllin classAbstractMapDecorator
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map- Overrides:
removein classAbstractMapDecorator
-
entrySet
public java.util.Set entrySet()
- Specified by:
entrySetin interfacejava.util.Map- Overrides:
entrySetin classAbstractMapDecorator
-
keySet
public java.util.Set keySet()
- Specified by:
keySetin interfacejava.util.Map- Overrides:
keySetin classAbstractMapDecorator
-
values
public java.util.Collection values()
- Specified by:
valuesin interfacejava.util.Map- Overrides:
valuesin classAbstractMapDecorator
-
removeValue
public java.lang.Object removeValue(java.lang.Object value)
Description copied from interface:BidiMapRemoves the key-value pair that is currently mapped to the specified value (optional operation).If the value is not contained in the map,
nullis returned.Implementations should seek to make this method perform equally as well as
remove(Object).- Specified by:
removeValuein interfaceBidiMap- Overrides:
removeValuein classAbstractBidiMapDecorator- Parameters:
value- the value to find the key-value pair for- Returns:
- the key that was removed,
nullif nothing removed
-
mapIterator
public MapIterator mapIterator()
Description copied from interface:BidiMapObtains aMapIteratorover the map.A map iterator is an efficient way of iterating over maps. It does not require that the map is stored using Map Entry objects which can increase performance.
BidiMap map = new DualHashBidiMap(); MapIterator it = map.mapIterator(); while (it.hasNext()) { Object key = it.next(); Object value = it.getValue(); it.setValue("newValue"); }- Specified by:
mapIteratorin interfaceBidiMap- Specified by:
mapIteratorin interfaceIterableMap- Overrides:
mapIteratorin classAbstractBidiMapDecorator- Returns:
- a map iterator
-
inverseBidiMap
public BidiMap 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- Overrides:
inverseBidiMapin classAbstractBidiMapDecorator- Returns:
- an inverted bidirectional map
-
-