org.apache.commons.collections.bidimap
Class UnmodifiableSortedBidiMap

java.lang.Object
  |
  +--org.apache.commons.collections.map.AbstractMapDecorator
        |
        +--org.apache.commons.collections.bidimap.AbstractBidiMapDecorator
              |
              +--org.apache.commons.collections.bidimap.AbstractOrderedBidiMapDecorator
                    |
                    +--org.apache.commons.collections.bidimap.AbstractSortedBidiMapDecorator
                          |
                          +--org.apache.commons.collections.bidimap.UnmodifiableSortedBidiMap
All Implemented Interfaces:
BidiMap, IterableMap, Map, OrderedBidiMap, OrderedMap, SortedBidiMap, SortedMap, Unmodifiable

public final class UnmodifiableSortedBidiMap
extends AbstractSortedBidiMapDecorator
implements Unmodifiable

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

Since:
Commons Collections 3.0
Version:
$Revision: 1.3 $ $Date: 2004/01/14 21:43:16 $
Author:
Stephen Colebourne

Inner classes inherited from class java.util.Map
Map.Entry
 
Fields inherited from class org.apache.commons.collections.map.AbstractMapDecorator
map
 
Method Summary
 void clear()
           
static SortedBidiMap decorate(SortedBidiMap map)
          Factory method to create an unmodifiable map.
 Set entrySet()
           
 SortedMap headMap(Object toKey)
           
 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.
 SortedBidiMap inverseSortedBidiMap()
          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).
 SortedMap subMap(Object fromKey, Object toKey)
           
 SortedMap tailMap(Object fromKey)
           
 Collection values()
           
 
Methods inherited from class org.apache.commons.collections.bidimap.AbstractSortedBidiMapDecorator
comparator, getSortedBidiMap
 
Methods inherited from class org.apache.commons.collections.bidimap.AbstractOrderedBidiMapDecorator
firstKey, getOrderedBidiMap, lastKey, nextKey, previousKey
 
Methods inherited from class org.apache.commons.collections.bidimap.AbstractBidiMapDecorator
getBidiMap, getKey
 
Methods inherited from class org.apache.commons.collections.map.AbstractMapDecorator
containsKey, containsValue, equals, get, getMap, hashCode, isEmpty, size, toString
 
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
 
Methods inherited from interface java.util.Map
containsKey, containsValue, equals, get, hashCode, isEmpty, size
 
Methods inherited from interface org.apache.commons.collections.OrderedMap
firstKey, lastKey, nextKey, previousKey
 
Methods inherited from interface java.util.SortedMap
firstKey, lastKey
 

Method Detail

decorate

public static SortedBidiMap decorate(SortedBidiMap map)
Factory method to create an unmodifiable map.
Parameters:
map - the map to decorate, must not be null
Throws:
IllegalArgumentException - if map is null

clear

public void clear()
Overrides:
clear in class AbstractMapDecorator

put

public Object put(Object key,
                  Object value)
Description copied from interface: BidiMap
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
 
Overrides:
put in class AbstractMapDecorator
Following copied from interface: org.apache.commons.collections.BidiMap
Parameters:
key - the key to store
value - the value to store
Returns:
the previous value mapped to this key
Throws:
UnsupportedOperationException - if the put method is not supported
ClassCastException - (optional) if the map limits the type of the value and the specified value is inappropriate
IllegalArgumentException - (optional) if the map limits the values in some way and the value was invalid
NullPointerException - (optional) if the map limits the values to non-null and null was specified

putAll

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

remove

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

entrySet

public Set entrySet()
Overrides:
entrySet in class AbstractMapDecorator

keySet

public Set keySet()
Overrides:
keySet in class AbstractMapDecorator

values

public Collection values()
Overrides:
values in class AbstractMapDecorator

removeValue

public Object removeValue(Object value)
Description copied from interface: BidiMap
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).

Overrides:
removeValue in class AbstractBidiMapDecorator
Following copied from interface: org.apache.commons.collections.BidiMap
Parameters:
value - the value to find the key-value pair for
Returns:
the key that was removed, null if nothing removed
Throws:
ClassCastException - (optional) if the map limits the type of the value and the specified value is inappropriate
NullPointerException - (optional) if the map limits the values to non-null and null was specified
UnsupportedOperationException - if this method is not supported by the implementation

mapIterator

public MapIterator mapIterator()
Description copied from interface: BidiMap
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");
 }
 
Overrides:
mapIterator in class AbstractBidiMapDecorator
Following copied from interface: org.apache.commons.collections.BidiMap
Returns:
a map iterator

inverseBidiMap

public BidiMap inverseBidiMap()
Description copied from interface: SortedBidiMap
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 a SortedBidiMap instance, usually by forwarding to inverseSortedBidiMap().

Overrides:
inverseBidiMap in class AbstractBidiMapDecorator
Following copied from interface: org.apache.commons.collections.SortedBidiMap
Returns:
an inverted bidirectional map

orderedMapIterator

public OrderedMapIterator orderedMapIterator()
Description copied from interface: OrderedMap
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();
 }
 
Overrides:
orderedMapIterator in class AbstractOrderedBidiMapDecorator
Following copied from interface: org.apache.commons.collections.OrderedMap
Returns:
a map iterator

inverseOrderedBidiMap

public OrderedBidiMap inverseOrderedBidiMap()
Description copied from interface: OrderedBidiMap
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.

Overrides:
inverseOrderedBidiMap in class AbstractOrderedBidiMapDecorator
Following copied from interface: org.apache.commons.collections.OrderedBidiMap
Returns:
an inverted bidirectional map

inverseSortedBidiMap

public SortedBidiMap inverseSortedBidiMap()
Description copied from interface: SortedBidiMap
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 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.

Overrides:
inverseSortedBidiMap in class AbstractSortedBidiMapDecorator
Following copied from interface: org.apache.commons.collections.SortedBidiMap
Returns:
an inverted bidirectional map

subMap

public SortedMap subMap(Object fromKey,
                        Object toKey)
Overrides:
subMap in class AbstractSortedBidiMapDecorator

headMap

public SortedMap headMap(Object toKey)
Overrides:
headMap in class AbstractSortedBidiMapDecorator

tailMap

public SortedMap tailMap(Object fromKey)
Overrides:
tailMap in class AbstractSortedBidiMapDecorator


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