edu.mit.ai.psg.utilities
Class ArrayMap

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--edu.mit.ai.psg.utilities.ArrayMap

public class ArrayMap
extends AbstractMap
implements Cloneable

ArrayMap is a implementation of Map which uses a simple trimmed array of alternating keys and values. Looking up a key is linear in the size of the map. Trimming minimizes space consumption at the cost of speed when adding or removing elements. Thus, ArrayMap is useful for applications with large numbers of small maps which are rarely resized. It is also easier to browse in a debugger than a hash table or tree, as debuggers can display the storage array as {key1, val1, key2, val2, ...}. The iterator is simple, and backed by the array; it may omit or repeat items if elements are removed or added during the iteration.


Constructor Summary
ArrayMap()
           
ArrayMap(Map initElements)
           
ArrayMap(Object[] initElements)
          initialize with array containing key1, val1, key2, val2, ...
 
Method Summary
 Object clone()
           
 Set entrySet()
           
 Object get(Object key)
           
 boolean isEmpty()
           
 Object put(Object key, Object newVal)
           
 Object remove(Object key)
           
 int size()
           
 
Methods inherited from class java.util.AbstractMap
clear, containsKey, containsValue, equals, hashCode, keySet, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArrayMap

public ArrayMap()

ArrayMap

public ArrayMap(Map initElements)

ArrayMap

public ArrayMap(Object[] initElements)
initialize with array containing key1, val1, key2, val2, ...
Method Detail

size

public int size()
Overrides:
size in class AbstractMap

isEmpty

public boolean isEmpty()
Overrides:
isEmpty in class AbstractMap

get

public Object get(Object key)
Overrides:
get in class AbstractMap

put

public Object put(Object key,
                  Object newVal)
Overrides:
put in class AbstractMap

remove

public Object remove(Object key)
Overrides:
remove in class AbstractMap

clone

public Object clone()
Overrides:
clone in class Object

entrySet

public Set entrySet()
Overrides:
entrySet in class AbstractMap

Copyright (c) 1996-1999
Massachusetts Institute of Technology

Feedback: jeva-feedback@ai.mit.edu