org.apache.commons.collections.bidimap

Class UnmodifiableOrderedBidiMap

Implemented Interfaces:
BidiMap, IterableMap, Map, OrderedBidiMap, OrderedMap, Unmodifiable

public final class UnmodifiableOrderedBidiMap
extends AbstractOrderedBidiMapDecorator
implements Unmodifiable

Decorates another OrderedBidiMap to ensure it can't be altered.

Version:
$Revision: 1.5 $ $Date: 2004/05/15 12:13:03 $

Author:
Stephen Colebourne

Since:
Commons Collections 3.0

Field Summary

Fields inherited from class org.apache.commons.collections.map.AbstractMapDecorator

map

Method Summary

void
clear()
static OrderedBidiMap
decorate(OrderedBidiMap map)
Factory method to create an unmodifiable map.
Set
entrySet()
BidiMap
inverseBidiMap()
Gets a view of this map where the keys and values are reversed.
OrderedBidiMap
inverseOrderedBidiMap()
Gets a view of this map where the keys and values are reversed.
Set
keySet()
MapIterator
mapIterator()
Obtains a MapIterator over the map.
OrderedMapIterator
orderedMapIterator()
Obtains an OrderedMapIterator over the map.
Object
put(Object key, Object value)
Puts the key-value pair into the map, replacing any previous pair.
void
putAll(Map mapToCopy)
Object
remove(Object key)
Object
removeValue(Object value)
Removes the key-value pair that is currently mapped to the specified value (optional operation).
Collection
values()

Methods inherited from class org.apache.commons.collections.bidimap.AbstractOrderedBidiMapDecorator

firstKey, getOrderedBidiMap, inverseOrderedBidiMap, lastKey, nextKey, orderedMapIterator, previousKey

Methods inherited from class org.apache.commons.collections.bidimap.AbstractBidiMapDecorator

getBidiMap, getKey, inverseBidiMap, mapIterator, removeValue

Methods inherited from class org.apache.commons.collections.map.AbstractMapDecorator

clear, containsKey, containsValue, entrySet, equals, get, getMap, hashCode, isEmpty, keySet, put, putAll, remove, size, toString, values

Method Details

clear

public void clear()
Overrides:
clear in interface AbstractMapDecorator


decorate

public static OrderedBidiMap decorate(OrderedBidiMap 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 OrderedBidiMap


entrySet

public Set entrySet()
Overrides:
entrySet in interface AbstractMapDecorator


inverseBidiMap

public BidiMap inverseBidiMap()
Gets 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.

Implementations must return an OrderedBidiMap instance, usually by forwarding to inverseOrderedBidiMap().

Specified by:
inverseBidiMap in interface OrderedBidiMap
inverseBidiMap in interface BidiMap
Overrides:
inverseBidiMap in interface AbstractBidiMapDecorator

Returns:
an inverted bidirectional map


inverseOrderedBidiMap

public OrderedBidiMap inverseOrderedBidiMap()
Gets 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:
inverseOrderedBidiMap in interface OrderedBidiMap
Overrides:
inverseOrderedBidiMap in interface AbstractOrderedBidiMapDecorator

Returns:
an inverted bidirectional map


keySet

public Set keySet()
Overrides:
keySet in interface AbstractMapDecorator


mapIterator

public MapIterator mapIterator()
Obtains a MapIterator over 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:
mapIterator in interface BidiMap
mapIterator in interface IterableMap
Overrides:
mapIterator in interface AbstractBidiMapDecorator

Returns:
a map iterator


orderedMapIterator

public OrderedMapIterator orderedMapIterator()
Obtains an OrderedMapIterator over the map.

A ordered map iterator is an efficient way of iterating over maps in both directions.

 BidiMap map = new TreeBidiMap();
 MapIterator it = map.mapIterator();
 while (it.hasNext()) {
   Object key = it.next();
   Object value = it.getValue();
   it.setValue("newValue");
   Object previousKey = it.previous();
 }
 
Specified by:
orderedMapIterator in interface OrderedMap
Overrides:
orderedMapIterator in interface AbstractOrderedBidiMapDecorator

Returns:
a map iterator


put

public Object put(Object key,
                  Object value)
Puts 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:
put in interface BidiMap
Overrides:
put in interface AbstractMapDecorator

Parameters:
key - the key to store
value - the value to store

Returns:
the previous value mapped to this key


putAll

public void putAll(Map mapToCopy)
Overrides:
putAll in interface AbstractMapDecorator


remove

public Object remove(Object key)
Overrides:
remove in interface AbstractMapDecorator


removeValue

public Object removeValue(Object value)
Removes the key-value pair that is currently mapped to the specified value (optional operation).

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).

Specified by:
removeValue in interface BidiMap
Overrides:
removeValue in interface AbstractBidiMapDecorator

Parameters:
value - the value to find the key-value pair for

Returns:
the key that was removed, null if nothing removed


values

public Collection values()
Overrides:
values in interface AbstractMapDecorator


Copyright © 2001-2005 Apache Software Foundation. All Rights Reserved.