org.apache.commons.collections.bidimap
Class UnmodifiableSortedBidiMap<K,V>

java.lang.Object
  extended by org.apache.commons.collections.map.AbstractMapDecorator<K,V>
      extended by org.apache.commons.collections.bidimap.AbstractBidiMapDecorator<K,V>
          extended by org.apache.commons.collections.bidimap.AbstractOrderedBidiMapDecorator<K,V>
              extended by org.apache.commons.collections.bidimap.AbstractSortedBidiMapDecorator<K,V>
                  extended by org.apache.commons.collections.bidimap.UnmodifiableSortedBidiMap<K,V>
All Implemented Interfaces:
Map<K,V>, SortedMap<K,V>, BidiMap<K,V>, IterableMap<K,V>, OrderedBidiMap<K,V>, OrderedMap<K,V>, SortedBidiMap<K,V>, Unmodifiable

public final class UnmodifiableSortedBidiMap<K,V>
extends AbstractSortedBidiMapDecorator<K,V>
implements Unmodifiable

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

Since:
Commons Collections 3.0
Version:
$Revision: 1.1.1.1 $ $Date: 2005/05/23 04:33:49 $
Author:
Matt Hall, John Watkinson, Stephen Colebourne

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
 
Fields inherited from class org.apache.commons.collections.map.AbstractMapDecorator
map
 
Method Summary
 void clear()
           
static
<K,V> SortedBidiMap<K,V>
decorate(SortedBidiMap<K,V> map)
          Factory method to create an unmodifiable map.
 Set<Map.Entry<K,V>> entrySet()
           
 SortedMap<K,V> headMap(K toKey)
           
 BidiMap<V,K> inverseBidiMap()
          Gets a view of this map where the keys and values are reversed.
 OrderedBidiMap<V,K> inverseOrderedBidiMap()
          Gets a view of this map where the keys and values are reversed.
 SortedBidiMap<V,K> inverseSortedBidiMap()
          Gets a view of this map where the keys and values are reversed.
 Set<K> keySet()
           
 MapIterator<K,V> mapIterator()
          Obtains a MapIterator over the map.
 OrderedMapIterator<K,V> orderedMapIterator()
          Obtains an OrderedMapIterator 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> mapToCopy)
           
 V remove(Object key)
           
 K removeValue(V value)
          Removes the key-value pair that is currently mapped to the specified value (optional operation).
 SortedMap<K,V> subMap(K fromKey, K toKey)
           
 SortedMap<K,V> tailMap(K fromKey)
           
 Collection<V> 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.Map
containsKey, containsValue, equals, get, hashCode, isEmpty, size
 
Methods inherited from interface java.util.SortedMap
firstKey, lastKey
 

Method Detail

decorate

public static <K,V> SortedBidiMap<K,V> decorate(SortedBidiMap<K,V> 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 SortedBidiMap
Throws:
IllegalArgumentException - if map is null

clear

public void clear()
Specified by:
clear in interface Map<K,V>
Overrides:
clear in class AbstractMapDecorator<K,V>

put

public V put(K key,
             V 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

Specified by:
put in interface Map<K,V>
Specified by:
put in interface BidiMap<K,V>
Overrides:
put in class AbstractMapDecorator<K,V>
Parameters:
key - the key to store
value - the value to store
Returns:
the previous value mapped to this key

putAll

public void putAll(Map<? extends K,? extends V> mapToCopy)
Specified by:
putAll in interface Map<K,V>
Overrides:
putAll in class AbstractMapDecorator<K,V>

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>
Overrides:
remove in class AbstractMapDecorator<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
Overrides:
entrySet in class AbstractMapDecorator<K,V>

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class AbstractMapDecorator<K,V>

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>
Overrides:
values in class AbstractMapDecorator<K,V>

removeValue

public K removeValue(V 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).

Specified by:
removeValue in interface BidiMap<K,V>
Overrides:
removeValue in class AbstractBidiMapDecorator<K,V>
Parameters:
value - the value to find the key-value pair for
Returns:
the key that was removed, null if nothing removed

mapIterator

public MapIterator<K,V> 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");
 }
 

Specified by:
mapIterator in interface BidiMap<K,V>
Specified by:
mapIterator in interface IterableMap<K,V>
Overrides:
mapIterator in class AbstractBidiMapDecorator<K,V>
Returns:
a map iterator

inverseBidiMap

public BidiMap<V,K> inverseBidiMap()
Description copied from interface: BidiMap
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 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:
inverseBidiMap in interface BidiMap<K,V>
Specified by:
inverseBidiMap in interface OrderedBidiMap<K,V>
Specified by:
inverseBidiMap in interface SortedBidiMap<K,V>
Overrides:
inverseBidiMap in class AbstractBidiMapDecorator<K,V>
Returns:
an inverted bidirectional map

orderedMapIterator

public OrderedMapIterator<K,V> 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();
 }
 

Specified by:
orderedMapIterator in interface OrderedMap<K,V>
Overrides:
orderedMapIterator in class AbstractOrderedBidiMapDecorator<K,V>
Returns:
a map iterator

inverseOrderedBidiMap

public OrderedBidiMap<V,K> 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.

Specified by:
inverseOrderedBidiMap in interface OrderedBidiMap<K,V>
Overrides:
inverseOrderedBidiMap in class AbstractOrderedBidiMapDecorator<K,V>
Returns:
an inverted bidirectional map

inverseSortedBidiMap

public SortedBidiMap<V,K> 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.

Specified by:
inverseSortedBidiMap in interface SortedBidiMap<K,V>
Overrides:
inverseSortedBidiMap in class AbstractSortedBidiMapDecorator<K,V>
Returns:
an inverted bidirectional map

subMap

public SortedMap<K,V> subMap(K fromKey,
                             K toKey)
Specified by:
subMap in interface SortedMap<K,V>
Overrides:
subMap in class AbstractSortedBidiMapDecorator<K,V>

headMap

public SortedMap<K,V> headMap(K toKey)
Specified by:
headMap in interface SortedMap<K,V>
Overrides:
headMap in class AbstractSortedBidiMapDecorator<K,V>

tailMap

public SortedMap<K,V> tailMap(K fromKey)
Specified by:
tailMap in interface SortedMap<K,V>
Overrides:
tailMap in class AbstractSortedBidiMapDecorator<K,V>


Copyright © 2005-2005 Apache Software Foundation, Matt Hall, John Watkinson. All Rights Reserved.