Top Description Fields Constructors Methods
org.apache.commons.collections4.map

public final Class UnmodifiableMap<K, V>

extends AbstractMapDecorator<K, V>
implements Unmodifiable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.commons.collections4.Unmodifiable
Type Parameters
<K>
the type of the keys in this map
<V>
the type of the values in this map
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.util.Collection, .Map, .Set, org.apache.commons.collections4.IterableMap, .MapIterator, .Unmodifiable, org.apache.commons.collections4.collection.UnmodifiableCollection, org.apache.commons.collections4.iterators.EntrySetMapIterator, .UnmodifiableMapIterator, org.apache.commons.collections4.set.UnmodifiableSet

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

This class is Serializable from Commons Collections 3.1.

Attempts to modify it will result in an UnsupportedOperationException.

Since
3.0

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Serialization version

Inherited from org.apache.commons.collections4.map.AbstractMapDecorator:
map

Constructor Summary

AccessConstructor and Description
private
UnmodifiableMap(final Map<? extends K, ? extends V>
the map to decorate, must not be null
map
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.clear.

Implements java.util.Map.clear, org.apache.commons.collections4.Put.clear.

Removes all of the mappings from this map (optional operation).
public Set<Map.Entry<K, V>>
public Set<K>
public MapIterator<K, V>
public V
put(final K
key with which the specified value is to be associated
key
,
final V
value to be associated with the specified key
value
)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.put.

Implements java.util.Map.put, org.apache.commons.collections4.Put.put.

Associates the specified value with the specified key in this map (optional operation).
public void
putAll(final Map<? extends K, ? extends V>
mappings to be stored in this map
mapToCopy
)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.putAll.

Implements java.util.Map.putAll, org.apache.commons.collections4.Put.putAll.

Copies all of the mappings from the specified map to this map (optional operation).
private void
readObject(final ObjectInputStream
the input stream
in
)

Read the map in using a custom routine.

public V
remove(final Object
key whose mapping is to be removed from the map
key
)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.remove.

Implements java.util.Map.remove, org.apache.commons.collections4.Get.remove.

Removes the mapping for a key from this map if it is present (optional operation).
public static <
the key type
K
,
the value type
V
>
Map<K, V>

Returns:

a new unmodifiable map
unmodifiableMap
(final Map<? extends K, ? extends V>
the map to decorate, must not be null
map
)

Factory method to create an unmodifiable map.

public Collection<V>
private void
writeObject(final ObjectOutputStream
the output stream
out
)

Write the map out using a custom routine.

Inherited from org.apache.commons.collections4.map.AbstractMapDecorator:
containsKeycontainsValuedecoratedequalsgethashCodeisEmptysizetoString

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version

Constructor Detail

UnmodifiableMapback to summary
private UnmodifiableMap(final Map<? extends K, ? extends V> map)

Constructor that wraps (not copies).

Parameters
map:Map<? extends K, ? extends V>

the map to decorate, must not be null

Annotations
@SuppressWarnings:unchecked
Exceptions
NullPointerException:
if map is null

Method Detail

clearback to summary
public void clear()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.clear.

Implements java.util.Map.clear, org.apache.commons.collections4.Put.clear.

Doc from java.util.Map.clear.

Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.

Annotations
@Override
entrySetback to summary
public Set<Map.Entry<K, V>> entrySet()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.entrySet.

Implements java.util.Map.entrySet, org.apache.commons.collections4.Get.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<Map.Entry<K, V>>

a set view of the mappings contained in this map

Annotations
@Override
keySetback to summary
public Set<K> keySet()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.keySet.

Implements java.util.Map.keySet, org.apache.commons.collections4.Get.keySet.

Doc from java.util.Map.keySet.

Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Returns:Set<K>

a set view of the keys contained in this map

Annotations
@Override
mapIteratorback to summary
public MapIterator<K, V> mapIterator()

Overrides org.apache.commons.collections4.map.AbstractIterableMap.mapIterator.

Implements org.apache.commons.collections4.IterableGet.mapIterator.

Doc from org.apache.commons.collections4.map.AbstractIterableMap.mapIterator.

Obtains a MapIterator over the map.

A map iterator is an efficient way of iterating over maps. There is no need to access the entry set or use Map Entry objects.

IterableMap<String,Integer> map = new HashedMap<String,Integer>();
MapIterator<String,Integer> it = map.mapIterator();
while (it.hasNext()) {
  String key = it.next();
  Integer value = it.getValue();
  it.setValue(value + 1);
}
Returns:MapIterator<K, V>

Doc from org.apache.commons.collections4.IterableGet.mapIterator.

a map iterator

Annotations
@Override
putback to summary
public V put(final K key, final V value)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.put.

Implements java.util.Map.put, org.apache.commons.collections4.Put.put.

Doc from java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for the key, the old value is replaced by the specified value. (A map m is said to contain a mapping for a key k if and only if m.containsKey(k) would return true.)

Parameters
key:K

key with which the specified value is to be associated

value:V

value to be associated with the specified key

Returns:V

the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key, if the implementation supports null values.)

Annotations
@Override
putAllback to summary
public void putAll(final Map<? extends K, ? extends V> mapToCopy)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.putAll.

Implements java.util.Map.putAll, org.apache.commons.collections4.Put.putAll.

Doc from java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. If the specified map has a defined encounter order, processing of its mappings generally occurs in that order.

Parameters
mapToCopy:Map<? extends K, ? extends V>

mappings to be stored in this map

Annotations
@Override
readObjectback to summary
private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException

Read the map in using a custom routine.

Parameters
in:ObjectInputStream

the input stream

Annotations
@SuppressWarnings:unchecked
Exceptions
IOException:
if an error occurs while reading from the stream
ClassNotFoundException:
if an object read from the stream can not be loaded
Since
3.1
removeback to summary
public V remove(final Object key)

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.remove.

Implements java.util.Map.remove, org.apache.commons.collections4.Get.remove.

Doc from java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation). More formally, if this map contains a mapping from key k to value v such that Objects.equals(key, k), that mapping is removed. (The map can contain at most one such mapping.)

Returns the value to which this map previously associated the key, or null if the map contained no mapping for the key.

If this map permits null values, then a return value of null does not necessarily indicate that the map contained no mapping for the key; it's also possible that the map explicitly mapped the key to null.

The map will not contain a mapping for the specified key once the call returns.

Parameters
key:Object

key whose mapping is to be removed from the map

Returns:V

the previous value associated with key, or null if there was no mapping for key.

Annotations
@Override
unmodifiableMapback to summary
public static <K, V> Map<K, V> unmodifiableMap(final Map<? extends K, ? extends V> map)

Factory method to create an unmodifiable map.

Parameters
<K>
the key type
<V>
the value type
map:Map<? extends K, ? extends V>

the map to decorate, must not be null

Returns:Map<K, V>

a new unmodifiable map

Exceptions
NullPointerException:
if map is null
Since
4.0
valuesback to summary
public Collection<V> values()

Overrides org.apache.commons.collections4.map.AbstractMapDecorator.values.

Implements java.util.Map.values, org.apache.commons.collections4.Get.values.

Doc from java.util.Map.values.

Returns a Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Collection<V>

a collection view of the values contained in this map

Annotations
@Override
writeObjectback to summary
private void writeObject(final ObjectOutputStream out) throws IOException

Write the map out using a custom routine.

Parameters
out:ObjectOutputStream

the output stream

Exceptions
IOException:
if an error occurs while writing to the stream
Since
3.1