org.norther.tammi.acorn.util
Class UnmodifiableMap

java.lang.Object
  extended by org.norther.tammi.acorn.util.UnmodifiableMap
All Implemented Interfaces:
Serializable, Cloneable, ConcurrentMap, Map, OrderedMap
Direct Known Subclasses:
ModifiableMap

public class UnmodifiableMap
extends Object
implements OrderedMap, Cloneable, Serializable

An unmodifiable map wrapper filtering out additions and removals.

Author:
Ilkka Priha
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
UnmodifiableMap()
          Constructs an empty map.
UnmodifiableMap(Map m)
          Constructs a new map.
 
Method Summary
 boolean add(int index, Object key, Object value)
          Associates the specified value with the specified key to the specified index in this map if not already mapped.
 boolean add(Object key, Object value)
          Associates the specified value with the specified key at the end of this map if not already mapped.
 void clear()
           
 Object clone()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 List entryList()
          Returns an ordered list of mapped entries.
 Set entrySet()
          Returns an ordered set of mapped entries.
 boolean equals(Object o)
           
 Object get(int index)
          Gets the indexed value in this map.
 Object get(Object key)
           
 Map.Entry getEntryAt(int index)
          Gets the indexed entry in this map.
 Object getKeyAt(int index)
          Gets the indexed key in this map.
protected  Map getMap()
          Gets the map adaptee.
 int hashCode()
           
 int indexOfKey(Object key)
          Returns the index of the specified key, or -1 if not found.
 boolean isEmpty()
           
 boolean isModifiable()
          Checks whether this map is modifiable.
protected  boolean isOrdered()
          Checks whether the wrapped map is ordered.
 List keyList()
          Returns an ordered list of mapped keys.
 Set keySet()
          Returns an ordered set of mapped keys.
 Object put(int index, Object key, Object value)
          Associates the specified value with the specified key to the specified index in this map.
 Object put(Object key, Object value)
           
 void putAll(Map m)
           
 Object putIfAbsent(int index, Object key, Object value)
          Associates the specified value with the specified key to the specified index in this map if not already mapped.
 Object putIfAbsent(Object key, Object value)
           
 Object remove(int index)
          Removes the indexed element in this map.
 Object remove(Object key)
           
 boolean remove(Object key, Object value)
           
 Object replace(int index, Object value)
          Replaces the indexed element in this map.
 Object replace(Object key, Object value)
           
 boolean replace(Object key, Object oldValue, Object newValue)
           
protected  void setMap(Map m)
          Sets the map adaptee.
 int size()
           
 String toString()
           
 List valueList()
          Returns an ordered list of mapped values.
 Collection values()
          Returns an ordered collection of mapped values.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UnmodifiableMap

public UnmodifiableMap()
Constructs an empty map.


UnmodifiableMap

public UnmodifiableMap(Map m)
Constructs a new map.

Parameters:
m - a map to wrap.
Method Detail

equals

public boolean equals(Object o)
Specified by:
equals in interface Map
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Map
Overrides:
hashCode in class Object

clone

public Object clone()
Overrides:
clone in class Object

clear

public void clear()
Specified by:
clear in interface Map

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map

entrySet

public Set entrySet()
Description copied from interface: OrderedMap
Returns an ordered set of mapped entries.

Specified by:
entrySet in interface Map
Specified by:
entrySet in interface OrderedMap
Returns:
a set of entries.

get

public Object get(Object key)
Specified by:
get in interface Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map

keySet

public Set keySet()
Description copied from interface: OrderedMap
Returns an ordered set of mapped keys.

Specified by:
keySet in interface Map
Specified by:
keySet in interface OrderedMap
Returns:
a set of keys.

put

public Object put(Object key,
                  Object value)
Specified by:
put in interface Map

putAll

public void putAll(Map m)
Specified by:
putAll in interface Map

remove

public Object remove(Object key)
Specified by:
remove in interface Map

size

public int size()
Specified by:
size in interface Map

values

public Collection values()
Description copied from interface: OrderedMap
Returns an ordered collection of mapped values.

Specified by:
values in interface Map
Specified by:
values in interface OrderedMap
Returns:
a collection of values.

toString

public String toString()
Overrides:
toString in class Object

putIfAbsent

public Object putIfAbsent(Object key,
                          Object value)
Specified by:
putIfAbsent in interface ConcurrentMap

replace

public Object replace(Object key,
                      Object value)
Specified by:
replace in interface ConcurrentMap

replace

public boolean replace(Object key,
                       Object oldValue,
                       Object newValue)
Specified by:
replace in interface ConcurrentMap

remove

public boolean remove(Object key,
                      Object value)
Specified by:
remove in interface ConcurrentMap

isModifiable

public boolean isModifiable()
Description copied from interface: OrderedMap
Checks whether this map is modifiable.

Specified by:
isModifiable in interface OrderedMap
Returns:
true for a modifiable map, false otherwise.

indexOfKey

public int indexOfKey(Object key)
Description copied from interface: OrderedMap
Returns the index of the specified key, or -1 if not found.

Specified by:
indexOfKey in interface OrderedMap
Parameters:
key - the key.
Returns:
the index of the key.

getKeyAt

public Object getKeyAt(int index)
Description copied from interface: OrderedMap
Gets the indexed key in this map.

Specified by:
getKeyAt in interface OrderedMap
Parameters:
index - the index.
Returns:
the indexed value.

get

public Object get(int index)
Description copied from interface: OrderedMap
Gets the indexed value in this map.

Specified by:
get in interface OrderedMap
Parameters:
index - the index.
Returns:
the indexed value.

getEntryAt

public Map.Entry getEntryAt(int index)
Description copied from interface: OrderedMap
Gets the indexed entry in this map.

Specified by:
getEntryAt in interface OrderedMap
Parameters:
index - the index.
Returns:
the indexed entry.

put

public Object put(int index,
                  Object key,
                  Object value)
Description copied from interface: OrderedMap
Associates the specified value with the specified key to the specified index in this map. Note that an existing key is not moved.

Specified by:
put in interface OrderedMap
Parameters:
index - the index.
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with the specified key.

putIfAbsent

public Object putIfAbsent(int index,
                          Object key,
                          Object value)
Description copied from interface: OrderedMap
Associates the specified value with the specified key to the specified index in this map if not already mapped.

Specified by:
putIfAbsent in interface OrderedMap
Parameters:
index - the index.
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with the specified key.

add

public boolean add(Object key,
                   Object value)
Description copied from interface: OrderedMap
Associates the specified value with the specified key at the end of this map if not already mapped.

Specified by:
add in interface OrderedMap
Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
true if added, false otherwise.

add

public boolean add(int index,
                   Object key,
                   Object value)
Description copied from interface: OrderedMap
Associates the specified value with the specified key to the specified index in this map if not already mapped.

Specified by:
add in interface OrderedMap
Parameters:
index - the index.
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
true if added, false otherwise.

replace

public Object replace(int index,
                      Object value)
Description copied from interface: OrderedMap
Replaces the indexed element in this map.

Specified by:
replace in interface OrderedMap
Parameters:
index - the index.
value - the new value.
Returns:
the replaced value.

remove

public Object remove(int index)
Description copied from interface: OrderedMap
Removes the indexed element in this map.

Specified by:
remove in interface OrderedMap
Parameters:
index - the index.
Returns:
the removed value.

keyList

public List keyList()
Description copied from interface: OrderedMap
Returns an ordered list of mapped keys.

Specified by:
keyList in interface OrderedMap
Returns:
a list of keys.

valueList

public List valueList()
Description copied from interface: OrderedMap
Returns an ordered list of mapped values.

Specified by:
valueList in interface OrderedMap
Returns:
a list of values.

entryList

public List entryList()
Description copied from interface: OrderedMap
Returns an ordered list of mapped entries.

Specified by:
entryList in interface OrderedMap
Returns:
a list of entries.

isOrdered

protected boolean isOrdered()
Checks whether the wrapped map is ordered.

Returns:
true if ordered, false otherwise.

getMap

protected Map getMap()
Gets the map adaptee.

Returns:
the wrapped map.

setMap

protected void setMap(Map m)
Sets the map adaptee.

Parameters:
m - the wrapped map.


Copyright © 2004 The Norther Organization. All rights reserved.