edu.stanford.nlp.util
Class DeltaMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by edu.stanford.nlp.util.DeltaMap<K,V>
All Implemented Interfaces:
java.util.Map<K,V>

public class DeltaMap<K,V>
extends java.util.AbstractMap<K,V>

A Map which wraps an original Map, and only stores the changes (deltas) from the original Map. This increases Map access time (roughly doubles it) but eliminates Map creation time and decreases memory usage (if you're keeping the original Map in memory anyway).

Author:
Teg Grenager (grenager@cs.stanford.edu)

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
DeltaMap(java.util.Map<K,V> originalMap)
           
DeltaMap(java.util.Map<K,V> originalMap, MapFactory<K,V> mf)
          This is very cheap.
 
Method Summary
 void clear()
          This is more expensive than normal.
 boolean containsKey(java.lang.Object key)
          This is more expensive.
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
          This is cheap.
 V get(java.lang.Object key)
          This may cost twice what it would in the original Map.
static void main(java.lang.String[] args)
          For testing only.
 V put(K key, V value)
          This may cost twice what it would in the original Map because we have to find the original value for this key.
 V remove(java.lang.Object key)
           
 
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DeltaMap

public DeltaMap(java.util.Map<K,V> originalMap,
                MapFactory<K,V> mf)
This is very cheap.

Parameters:
originalMap - will serve as the basis for this DeltaMap

DeltaMap

public DeltaMap(java.util.Map<K,V> originalMap)
Method Detail

containsKey

public boolean containsKey(java.lang.Object key)
This is more expensive.

Specified by:
containsKey in interface java.util.Map<K,V>
Overrides:
containsKey in class java.util.AbstractMap<K,V>
Parameters:
key - key whose presence in this map is to be tested.
Returns:
true if this map contains a mapping for the specified key.

get

public V get(java.lang.Object key)
This may cost twice what it would in the original Map.

Specified by:
get in interface java.util.Map<K,V>
Overrides:
get in class java.util.AbstractMap<K,V>
Parameters:
key - key whose associated value is to be returned.
Returns:
the value to which this map maps the specified key, or null if the map contains no mapping for this key.

put

public V put(K key,
             V value)
This may cost twice what it would in the original Map because we have to find the original value for this key.

Specified by:
put in interface java.util.Map<K,V>
Overrides:
put in class java.util.AbstractMap<K,V>
Parameters:
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 specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.

remove

public V remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<K,V>
Overrides:
remove in class java.util.AbstractMap<K,V>

clear

public void clear()
This is more expensive than normal.

Specified by:
clear in interface java.util.Map<K,V>
Overrides:
clear in class java.util.AbstractMap<K,V>

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
This is cheap.

Specified by:
entrySet in interface java.util.Map<K,V>
Specified by:
entrySet in class java.util.AbstractMap<K,V>
Returns:
a set view of the mappings contained in this map.

main

public static void main(java.lang.String[] args)
For testing only.

Parameters:
args - from command line


Stanford NLP Group