TUM CCSM Commons

edu.tum.cs.commons.collections
Class UnmodifiableSortedMap<K,V>

java.lang.Object
  extended by edu.tum.cs.commons.collections.UnmodifiableMap<K,V>
      extended by edu.tum.cs.commons.collections.UnmodifiableSortedMap<K,V>
All Implemented Interfaces:
java.io.Serializable, java.util.Map<K,V>, java.util.SortedMap<K,V>

public class UnmodifiableSortedMap<K,V>
extends UnmodifiableMap<K,V>
implements java.util.SortedMap<K,V>

This is a wrapper for a SortedMap prohibiting all calls which would modify its contents. As the construction of this class is performed in constant time it is prefered over copying the map (which takes linear time). Using this class is also preferred to using the unmodifiableX() in class Collections as they return the collection base type that does not signal, that the object ist unmodifiable. Using the classes in this package makes unmodifiability more explicit.

All prohibited methods throw an UnsupportedOperationException. The class is nearly the same as the one returned by Collections.unmodifiableSortedMap(SortedMap), but by making it a public class we can make the return value of some methods more explicit.

Version:
$Revision: 26283 $
Author:
Benjamin Hummel, $Author: juergens $
See Also:
Serialized Form
Rating:
GREEN Hash: ABDE6CF5CE63ADC67CA6BB5BB9D17737

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
UnmodifiableSortedMap(java.util.SortedMap<K,V> m)
          Creates a new unmodifiable sorted map from another sorted map.
 
Method Summary
 java.util.Comparator<? super K> comparator()
          
 K firstKey()
          
 UnmodifiableSortedMap<K,V> headMap(K toKey)
          
 K lastKey()
          
 UnmodifiableSortedMap<K,V> subMap(K fromKey, K toKey)
          
 UnmodifiableSortedMap<K,V> tailMap(K fromKey)
          
 
Methods inherited from class edu.tum.cs.commons.collections.UnmodifiableMap
clear, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, toString, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.SortedMap
entrySet, keySet, values
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, put, putAll, remove, size
 

Constructor Detail

UnmodifiableSortedMap

public UnmodifiableSortedMap(java.util.SortedMap<K,V> m)
Creates a new unmodifiable sorted map from another sorted map. All modifications to the underlying map will directly be visible in this wrapper.

Method Detail

comparator

public java.util.Comparator<? super K> comparator()

Specified by:
comparator in interface java.util.SortedMap<K,V>

firstKey

public K firstKey()

Specified by:
firstKey in interface java.util.SortedMap<K,V>

headMap

public UnmodifiableSortedMap<K,V> headMap(K toKey)

Specified by:
headMap in interface java.util.SortedMap<K,V>

lastKey

public K lastKey()

Specified by:
lastKey in interface java.util.SortedMap<K,V>

subMap

public UnmodifiableSortedMap<K,V> subMap(K fromKey,
                                         K toKey)

Specified by:
subMap in interface java.util.SortedMap<K,V>

tailMap

public UnmodifiableSortedMap<K,V> tailMap(K fromKey)

Specified by:
tailMap in interface java.util.SortedMap<K,V>

TUM CCSM Commons

TUM CCSM Commons - 2.7