edu.stanford.nlp.util
Class DeltaMap

java.lang.Object
  extended by java.util.AbstractMap
      extended by edu.stanford.nlp.util.DeltaMap
All Implemented Interfaces:
Map

public class DeltaMap
extends AbstractMap
implements Map

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) Date: Jan 9, 2004 Time: 9:19:06 AM

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

Constructor Detail

DeltaMap

public DeltaMap(Map originalMap,
                MapFactory mf)
This is very cheap.

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

DeltaMap

public DeltaMap(Map originalMap)
Method Detail

containsKey

public boolean containsKey(Object key)
This is expensive.

Specified by:
containsKey in interface Map
Overrides:
containsKey in class AbstractMap
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 Object get(Object key)
This may cost twice what it would in the original Map.

Specified by:
get in interface Map
Overrides:
get in class AbstractMap
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 Object put(Object key,
                  Object 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 Map
Overrides:
put in class AbstractMap
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 Object remove(Object key)
Specified by:
remove in interface Map
Overrides:
remove in class AbstractMap

clear

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

Specified by:
clear in interface Map
Overrides:
clear in class AbstractMap

entrySet

public Set entrySet()
This is cheap.

Specified by:
entrySet in interface Map
Specified by:
entrySet in class AbstractMap
Returns:
a set view of the mappings contained in this map.

main

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

Parameters:
args - from command line


Stanford NLP Group