org.apache.commons.collections.map

Class UnmodifiableMap

Implemented Interfaces:
IterableMap, Map, Serializable, Unmodifiable

public final class UnmodifiableMap
extends AbstractMapDecorator
implements IterableMap, Unmodifiable, Serializable

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

This class is Serializable from Commons Collections 3.1.

Version:
$Revision: 1.10 $ $Date: 2004/04/09 10:32:25 $
Author:
Stephen Colebourne
Since:
Commons Collections 3.0

Field Summary

Fields inherited from class org.apache.commons.collections.map.AbstractMapDecorator

map

Method Summary

void
clear()
static Map
decorate(Map map)
Factory method to create an unmodifiable map.
Set
entrySet()
Set
keySet()
MapIterator
mapIterator()
Obtains a MapIterator over the map.
Object
put(Object key, Object value)
void
putAll(Map mapToCopy)
Object
remove(Object key)
Collection
values()

Methods inherited from class org.apache.commons.collections.map.AbstractMapDecorator

clear, containsKey, containsValue, entrySet, equals, get, getMap, hashCode, isEmpty, keySet, put, putAll, remove, size, toString, values

Method Details

clear

public void clear()
Overrides:
clear in interface AbstractMapDecorator

decorate

public static Map decorate(Map map)
Factory method to create an unmodifiable map.
Parameters:
map - the map to decorate, must not be null

entrySet

public Set entrySet()
Overrides:
entrySet in interface AbstractMapDecorator

keySet

public Set keySet()
Overrides:
keySet in interface AbstractMapDecorator

mapIterator

public MapIterator 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 cast to Map Entry objects.

 IterableMap map = new HashedMap();
 MapIterator it = map.mapIterator();
 while (it.hasNext()) {
   Object key = it.next();
   Object value = it.getValue();
   it.setValue("newValue");
 }
 
Specified by:
mapIterator in interface IterableMap
Returns:
a map iterator

put

public Object put(Object key,
                  Object value)
Overrides:
put in interface AbstractMapDecorator

putAll

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

remove

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

values

public Collection values()
Overrides:
values in interface AbstractMapDecorator

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