util
Class VectorizedMap

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--java.util.TreeMap
              |
              +--util.VectorizedMap
All Implemented Interfaces:
Cloneable, Map, Serializable, SortedMap

public class VectorizedMap
extends TreeMap

VectorizedMap is a sorted map that also keeps track of the object's insertion order. You can get elements from this map by their natural order (determined by compareTo) or by when they were added to this map.

See Also:
Cloneable, Serializable, SortedMap, Serialized Form

Inner classes inherited from class java.util.Map
Map.Entry
 
Field Summary
protected  Vector vContainer
          A Vector to keep track of insertion order.
 
Constructor Summary
VectorizedMap()
          Creates a new VectorizedMap instance.
VectorizedMap(Map m)
          Creates a new VectorizedMap instance from an existing map.
 
Method Summary
 void clear()
          Removes all mappings from this map.
 Object elementAtByInsertionOrder(int i)
          Returns the value of the key-value pair at the specified insertion index.
 boolean equals(Object o)
          Compares the specified object with this map for equality.
 int indexOfKeyByInsertionOrder(Object oKey)
          Returns the rank of the given key based on the order of insertion.
 Integer[] indexOfValueByInsertionOrder(Object oValue)
          Returns an Integer array of all the ranks of the given value based on the order of insertion.
 Object keyAtByInsertionOrder(int i)
          Returns the key of the key-value pair at the specified insertion index.
 Vector keysByInsertionOrder()
           
 Object nextKeyByInsertionOrder(int iCurrent)
          A convenience method that returns the next key of the key-value pair that comes after the given index based on the order of insertion.
 Object nextKeyByInsertionOrder(Object oCurrentKey)
          A convenience method that returns the next key of the key-value pair that comes after the given key based on the order of insertion.
 Object put(Object oKey, Object oValue)
          Associates the specified value with the specified key in this map.
 void putAll(Map m)
          This is an unsupported opertion, because a regular map does not maintain the insertion order of its elements.
 Object remove(Object oKey)
          Removes the mapping for this key from this map if present.
 Object valueAtByInsertionOrder(int i)
          Returns the value of the key-value pair at the specified insertion index.
 
Methods inherited from class java.util.TreeMap
clone, comparator, containsKey, containsValue, entrySet, firstKey, get, headMap, keySet, lastKey, size, subMap, tailMap, values
 
Methods inherited from class java.util.AbstractMap
hashCode, isEmpty, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
hashCode, isEmpty
 

Field Detail

vContainer

protected Vector vContainer
A Vector to keep track of insertion order.
Constructor Detail

VectorizedMap

public VectorizedMap()
Creates a new VectorizedMap instance.

VectorizedMap

public VectorizedMap(Map m)
Creates a new VectorizedMap instance from an existing map. Warning: the order of entry of the initial map will not be preserved.
Parameters:
m - a Map value
Method Detail

put

public Object put(Object oKey,
                  Object oValue)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced. This object will be chronologially last when the map is queried by insertion order.
Overrides:
put in class TreeMap
Parameters:
oKey - key with which the specified value is to be associated.
oValue - 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 oKey)
Removes the mapping for this key from this map if present.
Overrides:
remove in class TreeMap
Parameters:
oKey - key whose mapping is to be removed from the map.
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.

putAll

public void putAll(Map m)
This is an unsupported opertion, because a regular map does not maintain the insertion order of its elements.
Overrides:
putAll in class TreeMap
Parameters:
m - Mappings to be stored in this map.

clear

public void clear()
Removes all mappings from this map.
Overrides:
clear in class TreeMap

equals

public boolean equals(Object o)
Compares the specified object with this map for equality. Returns true if the given object is also a VectorizedMap and the two VectorizedMaps represent the same mappings, with the same order of insertions of its elements. More formally, two maps t1 and t2 represent the same mappings if t1.entrySet().equals(t2.entrySet()). This ensures that the equals method works properly across different implementations of the Map interface.
Overrides:
equals in class AbstractMap
Parameters:
o - object to be compared for equality with this map.
Returns:
true if the specified object is equal to this map.

keyAtByInsertionOrder

public Object keyAtByInsertionOrder(int i)
Returns the key of the key-value pair at the specified insertion index. For example, if int = 0, then this method will return the first key entered into the map.
Parameters:
i - the index of the desired key
Returns:
the key of the key-value pair at the specified insertion index.

valueAtByInsertionOrder

public Object valueAtByInsertionOrder(int i)
Returns the value of the key-value pair at the specified insertion index. For example, if int = 0, then this method will return the first value entered into the map.
Parameters:
i - the index of the desired value
Returns:
the value of the key-value pair at the specified insertion index.

elementAtByInsertionOrder

public Object elementAtByInsertionOrder(int i)
Returns the value of the key-value pair at the specified insertion index. For example, if int = 0, then this method will return the first value entered into the map.
Parameters:
i - the index of the desired value
Returns:
the value of the key-value pair at the specified insertion index.

indexOfKeyByInsertionOrder

public int indexOfKeyByInsertionOrder(Object oKey)
Returns the rank of the given key based on the order of insertion.
Parameters:
oKey - the key to check.
Returns:
the rank of the given key based on the order of insertion.

indexOfValueByInsertionOrder

public Integer[] indexOfValueByInsertionOrder(Object oValue)
Returns an Integer array of all the ranks of the given value based on the order of insertion.
Parameters:
oValue - the value to check.
Returns:
an Integer array of all the ranks of the given value based on the order of insertion.

nextKeyByInsertionOrder

public Object nextKeyByInsertionOrder(int iCurrent)
A convenience method that returns the next key of the key-value pair that comes after the given index based on the order of insertion.
Parameters:
iCurrent - the index of the the current key-value pair based on the order of insertion.
Returns:
the next key of the key-value pair that comes after the given index based on the order of insertion.

nextKeyByInsertionOrder

public Object nextKeyByInsertionOrder(Object oCurrentKey)
A convenience method that returns the next key of the key-value pair that comes after the given key based on the order of insertion.
Parameters:
oCurrentKey - the value the the current key-value pair based on the order of insertion.
Returns:
the next key of the key-value pair that comes after the given index based on the order of insertion.

keysByInsertionOrder

public Vector keysByInsertionOrder()