org.cdlib.xtf.util
Class ConsecutiveMap

Object
  extended by ConsecutiveMap

public class ConsecutiveMap
extends Object

Implements a simple mapping, from object keys to integers. Each new key is assigned a consecutive number, starting at zero.

Author:
Martin Haye

Field Summary
private  Vector inOrder
          Vector of all unique keys, in order of addition
private  HashMap map
          Mapping used to keep the unique set of keys
 
Constructor Summary
ConsecutiveMap()
           
 
Method Summary
 int get(Object key)
          Retrieve the namecode for the given key.
 Object[] getArray()
          Retrieve an array of all the keys, ordered by consecutive number.
 boolean has(Object key)
          Check if the given key is present in the map yet.
 int put(Object key)
          If the key is already present in the map, return its assigned number.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private HashMap map
Mapping used to keep the unique set of keys


inOrder

private Vector inOrder
Vector of all unique keys, in order of addition

Constructor Detail

ConsecutiveMap

public ConsecutiveMap()
Method Detail

put

public int put(Object key)
If the key is already present in the map, return its assigned number. Otherwise, add it and assign it a new number.

Parameters:
key - The key to look up
Returns:
A number associated with that key

get

public int get(Object key)
Retrieve the namecode for the given key. If not found, returns -1.


has

public boolean has(Object key)
Check if the given key is present in the map yet.


getArray

public Object[] getArray()
Retrieve an array of all the keys, ordered by consecutive number.