common
Class HashMapDiff

java.lang.Object
  extended by java.util.AbstractMap
      extended by common.HashMapDiff
All Implemented Interfaces:
MapDiff, java.lang.Cloneable, java.util.Map

public class HashMapDiff
extends java.util.AbstractMap
implements MapDiff, java.lang.Cloneable

MapDiff implementation that uses a HashMap to store the values for changed keys, and a HashSet to store the removed keys. This implementation does not support null values.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
HashMapDiff(java.util.Map underlying)
          Creates a new HashMapDiff with the given underlying map.
 
Method Summary
 void changeUnderlying()
          Changes the underlying map so it is equal to this map.
 void clearChanges()
          Resets this map so it is equal to the underlying map.
 java.lang.Object clone()
           
 boolean containsKey(java.lang.Object key)
           
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 java.util.Set getChangedKeys()
          Returns the set of keys that map to different values in this map than in the underlying map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 java.lang.Object remove(java.lang.Object key)
           
 int size()
           
 
Methods inherited from class java.util.AbstractMap
clear, containsValue, equals, hashCode, isEmpty, keySet, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsValue, equals, hashCode, isEmpty, keySet, putAll, values
 

Constructor Detail

HashMapDiff

public HashMapDiff(java.util.Map underlying)
Creates a new HashMapDiff with the given underlying map.

Method Detail

containsKey

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

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map
Overrides:
get in class java.util.AbstractMap

size

public int size()
Specified by:
size in interface java.util.Map
Overrides:
size in class java.util.AbstractMap

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.AbstractMap

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map
Overrides:
remove in class java.util.AbstractMap

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map
Specified by:
entrySet in class java.util.AbstractMap

getChangedKeys

public java.util.Set getChangedKeys()
Description copied from interface: MapDiff
Returns the set of keys that map to different values in this map than in the underlying map. This includes any keys that have values in this map but not the underlying map, or vice versa.

The returned set may or may not be kept up to date as changes are made to this MapDiff.

Specified by:
getChangedKeys in interface MapDiff
Returns:
unmodifiable Set of Object

changeUnderlying

public void changeUnderlying()
Description copied from interface: MapDiff
Changes the underlying map so it is equal to this map.

Specified by:
changeUnderlying in interface MapDiff

clearChanges

public void clearChanges()
Description copied from interface: MapDiff
Resets this map so it is equal to the underlying map.

Specified by:
clearChanges in interface MapDiff

clone

public java.lang.Object clone()
Overrides:
clone in class java.util.AbstractMap