TUM CCSM Commons

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

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

public class UnmodifiableMap<K,V>
extends java.lang.Object
implements java.util.Map<K,V>, java.io.Serializable

This is a wrapper for a Map 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.unmodifiableMap(Map), but by making it a public class we can make the return value of some methods more explicit.

This map is serializable if the wrapped map is serializable.

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

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
UnmodifiableMap(java.util.Map<K,V> m)
          Creates a new unmodifiable map from another map.
 
Method Summary
 void clear()
          Operation is not supported.
 boolean containsKey(java.lang.Object key)
          
 boolean containsValue(java.lang.Object value)
          
 UnmodifiableSet<java.util.Map.Entry<K,V>> entrySet()
          
 V get(java.lang.Object key)
          
 boolean isEmpty()
          
 UnmodifiableSet<K> keySet()
          
 V put(K arg0, V arg1)
          Operation is not supported.
 void putAll(java.util.Map<? extends K,? extends V> arg0)
          Operation is not supported.
 V remove(java.lang.Object arg0)
          Operation is not supported.
 int size()
          
 java.lang.String toString()
          Returns a string representation of this map.
 UnmodifiableCollection<V> values()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

UnmodifiableMap

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

Method Detail

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface java.util.Map<K,V>

size

public int size()

Specified by:
size in interface java.util.Map<K,V>

containsKey

public boolean containsKey(java.lang.Object key)

Specified by:
containsKey in interface java.util.Map<K,V>

containsValue

public boolean containsValue(java.lang.Object value)

Specified by:
containsValue in interface java.util.Map<K,V>

get

public V get(java.lang.Object key)

Specified by:
get in interface java.util.Map<K,V>

keySet

public UnmodifiableSet<K> keySet()

Specified by:
keySet in interface java.util.Map<K,V>

values

public UnmodifiableCollection<V> values()

Specified by:
values in interface java.util.Map<K,V>

entrySet

public UnmodifiableSet<java.util.Map.Entry<K,V>> entrySet()

Specified by:
entrySet in interface java.util.Map<K,V>

clear

public void clear()
Operation is not supported.

Specified by:
clear in interface java.util.Map<K,V>
Throws:
java.lang.UnsupportedOperationException

put

public V put(K arg0,
             V arg1)
Operation is not supported.

Specified by:
put in interface java.util.Map<K,V>
Throws:
java.lang.UnsupportedOperationException

putAll

public void putAll(java.util.Map<? extends K,? extends V> arg0)
Operation is not supported.

Specified by:
putAll in interface java.util.Map<K,V>
Throws:
java.lang.UnsupportedOperationException

remove

public V remove(java.lang.Object arg0)
Operation is not supported.

Specified by:
remove in interface java.util.Map<K,V>
Throws:
java.lang.UnsupportedOperationException

toString

public java.lang.String toString()
Returns a string representation of this map.

Overrides:
toString in class java.lang.Object

TUM CCSM Commons

TUM CCSM Commons - 2.7