QJCC homepage

biz.chitec.quarterback.util
Class HiddenDefaultValueMap

java.lang.Object
  extended bybiz.chitec.quarterback.util.HiddenDefaultValueMap
All Implemented Interfaces:
java.util.Map

public class HiddenDefaultValueMap
extends java.lang.Object
implements java.util.Map

Map which returns default values of a second map if the first map has no content. All changes go to the first map. Any entry in the first map hides whatever is in the second map.

Version:
$Id: 84d19603ae2f094b8921251f2eb93060a7ee04a0 $
Author:
cantamen/Dirk Hillbrecht 2007. Released under the GPL.

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
private  java.util.Map firstmap
           
private  java.util.Map secondmap
           
 
Constructor Summary
HiddenDefaultValueMap(java.util.Map firstmapx, java.util.Map secondmapx)
          Instantiates the maps which back the special purpose map.
 
Method Summary
 void clear()
          Clears only the first map.
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
          Return a set of all entries in the map.
 java.lang.Object get(java.lang.Object key)
          Returns value stored under the given key.
 boolean isEmpty()
          Returns whether both maps are empty.
 java.util.Set keySet()
          Return a set of all keys in the map, i.e. each key in the first and in the second map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Puts a value into the map, which means that it is stored in firstmap.
 void putAll(java.util.Map t)
          Puts all given data into the first map.
 java.lang.Object remove(java.lang.Object key)
          Removes an object from the first map.
 int size()
          Returns the size of the combined table which is the number of all keys, excluding the duplicates.
 java.util.Collection values()
          Returns all values in both maps as simple union.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

firstmap

private java.util.Map firstmap

secondmap

private java.util.Map secondmap
Constructor Detail

HiddenDefaultValueMap

public HiddenDefaultValueMap(java.util.Map firstmapx,
                             java.util.Map secondmapx)
Instantiates the maps which back the special purpose map.

Method Detail

clear

public void clear()
Clears only the first map.

Specified by:
clear in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map

entrySet

public java.util.Set entrySet()
Return a set of all entries in the map. If first and second map contain the same key, only and always the mapping in firstmap is returned. Note that due to the nature of the whole thing, the returned set is NOT backed by the map! Changes in the map are not reflected in the Set. Especially, they do not throw a ConcurrentModificationException. The returned set itself is unmodifiable.

Specified by:
entrySet in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)
Returns value stored under the given key. If firstmap contains the key, it is returned. Otherwise, secondmap is asked.

Specified by:
get in interface java.util.Map

isEmpty

public boolean isEmpty()
Returns whether both maps are empty.

Specified by:
isEmpty in interface java.util.Map

keySet

public java.util.Set keySet()
Return a set of all keys in the map, i.e. each key in the first and in the second map. Note that due to the nature of the whole thing, the returned set is NOT backed by the map! Changes in the map are not reflected in the Set. Especially, they do not throw a ConcurrentModificationException. The returned set itself is unmodifiable.

Specified by:
keySet in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Puts a value into the map, which means that it is stored in firstmap. This method does always store the data in the first map. The second map is, as it is the main reasoning behind this whole object, unchanged.

Specified by:
put in interface java.util.Map

putAll

public void putAll(java.util.Map t)
Puts all given data into the first map.

Specified by:
putAll in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
Removes an object from the first map. Note that does NOW ALWAYS mean that there is no mapping for the given key any more after this operation. It might be that the mapping in the first map only hid the mapping in the second one. That hidden mapping would become visible again after the remove operation. If the mapping comes from the second map, it cannot be deleted at all, the remove operation will have no effect.

Specified by:
remove in interface java.util.Map

size

public int size()
Returns the size of the combined table which is the number of all keys, excluding the duplicates.

Specified by:
size in interface java.util.Map

values

public java.util.Collection values()
Returns all values in both maps as simple union. Note that due to the nature of the whole thing, the returned collection is NOT backed by the map! Changes in the map are not reflected in the Set. Especially, they do not throw a ConcurrentModificationException. The returned set itself is unmodifiable.

Specified by:
values in interface java.util.Map

QJCC homepage