org.pf.util
Class StackedMap

java.lang.Object
  extended by org.pf.util.MapWrapper
      extended by org.pf.util.StackedMap
All Implemented Interfaces:
java.io.Serializable, java.util.Map

public class StackedMap
extends MapWrapper

Provides a map that allows to push() and pop() internal settings to/from a (LIFO) stack. Accessing an element via get(key) always looks in the last map and then continues looking for it (if not found) in the next map on the stack.

Version:
1.0
Author:
Manfred Duchrow
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
StackedMap()
          Initialize the new instance with default values.
StackedMap(java.util.Map map)
          Initialize the new instance with an internal map.
 
Method Summary
 void clear()
          Removes all entries from this map, but not from the maps on the stack!
 boolean containsKey(java.lang.Object key)
          This method returns true, if the given key can be found in this map or any map on the stack.
 boolean containsValue(java.lang.Object value)
          This method returns true, if the given value is a value of any entry in this map or any map on the stack.
 java.util.Set entrySet()
          Returns all entries of the map and all stacked maps.
 java.lang.Object get(java.lang.Object key)
          Returns the object that was registered under the specified key in this map or in any of the maps on the stack.
 boolean isEmpty()
          Returns true, if there is no entry in this map and in all maps on the stack.
 java.util.Set keySet()
          Returns all keys in this map and the maps on the stack
 java.util.Map pop()
          Removes the map at the top of this stack and returns that map as the value of this function.
 void push()
          Pushes the an newly created map onto the top of this stack.
 void push(java.util.Map map)
          Pushes the given map onto the top of this stack.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Puts the given value under the specified key into this map.
 void putAll(java.util.Map map)
          Each entry of the given map will be added to this map.
 java.lang.Object remove(java.lang.Object key)
          Removes the entry with the specified key from this map.
 int size()
          Returns how many entries currently are in this map and the maps on the stack.
 java.util.Collection values()
          Returns all values of this map and the maps on the stack.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

StackedMap

public StackedMap()
Initialize the new instance with default values.


StackedMap

public StackedMap(java.util.Map map)
Initialize the new instance with an internal map.

Method Detail

clear

public void clear()
Removes all entries from this map, but not from the maps on the stack!

Specified by:
clear in interface java.util.Map
Overrides:
clear in class MapWrapper
See Also:
Map.clear()

containsKey

public boolean containsKey(java.lang.Object key)
This method returns true, if the given key can be found in this map or any map on the stack.

Specified by:
containsKey in interface java.util.Map
Overrides:
containsKey in class MapWrapper
See Also:
Map.containsKey(Object)

containsValue

public boolean containsValue(java.lang.Object value)
This method returns true, if the given value is a value of any entry in this map or any map on the stack.

Specified by:
containsValue in interface java.util.Map
Overrides:
containsValue in class MapWrapper
See Also:
Map.containsValue(Object)

entrySet

public java.util.Set entrySet()
Returns all entries of the map and all stacked maps.

Specified by:
entrySet in interface java.util.Map
Overrides:
entrySet in class MapWrapper
See Also:
Map.entrySet()

get

public java.lang.Object get(java.lang.Object key)
Returns the object that was registered under the specified key in this map or in any of the maps on the stack.

Specified by:
get in interface java.util.Map
Overrides:
get in class MapWrapper
See Also:
Map.get(Object)

isEmpty

public boolean isEmpty()
Returns true, if there is no entry in this map and in all maps on the stack.

Specified by:
isEmpty in interface java.util.Map
Overrides:
isEmpty in class MapWrapper
See Also:
Map.isEmpty()

keySet

public java.util.Set keySet()
Returns all keys in this map and the maps on the stack

Specified by:
keySet in interface java.util.Map
Overrides:
keySet in class MapWrapper
See Also:
Map.keySet()

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Puts the given value under the specified key into this map.

Specified by:
put in interface java.util.Map
Overrides:
put in class MapWrapper
See Also:
Map.put(Object, Object)

putAll

public void putAll(java.util.Map map)
Each entry of the given map will be added to this map.

Specified by:
putAll in interface java.util.Map
Overrides:
putAll in class MapWrapper
See Also:
Map.putAll(Map)

remove

public java.lang.Object remove(java.lang.Object key)
Removes the entry with the specified key from this map. It will not be removed from any map on the stack.

Specified by:
remove in interface java.util.Map
Overrides:
remove in class MapWrapper
See Also:
Map.remove(Object)

size

public int size()
Returns how many entries currently are in this map and the maps on the stack.

Specified by:
size in interface java.util.Map
Overrides:
size in class MapWrapper
See Also:
Map.size()

values

public java.util.Collection values()
Returns all values of this map and the maps on the stack.

Specified by:
values in interface java.util.Map
Overrides:
values in class MapWrapper
See Also:
Map.values()

push

public void push(java.util.Map map)
Pushes the given map onto the top of this stack.


push

public void push()
Pushes the an newly created map onto the top of this stack.


pop

public java.util.Map pop()
Removes the map at the top of this stack and returns that map as the value of this function.