gov.nih.nlm.util
Class OrderedHashMap

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap
          extended by gov.nih.nlm.util.OrderedHashMap
All Implemented Interfaces:
Serializable, Cloneable, Map

public class OrderedHashMap
extends HashMap

A HashMap that maintains the order in which elements were added.

Author:
Stephanie Halbeisen
See Also:
Serialized Form

Constructor Summary
OrderedHashMap()
          Instantiates an empty OrderedHashMap.
OrderedHashMap(int capacity)
          Instantiates an empty OrderedHashMap with the specified capacity.
OrderedHashMap(int capacity, float load_factor)
          Instantiates an empty OrderedHashMap with the specified capacity and load factor.
OrderedHashMap(Map map)
          Instantiates an OrderedHashMap from an existing Map.
 
Method Summary
 void clear()
          Clears the map.
 Object getKey(int index)
          Returns the Object key for a specified index.
 Object getValue(int index)
          Returns the Object value for a specified index.
 List orderedKeySet()
          Returns the key set as an ordered List.
 Object put(Object key, Object value)
          Adds a key/value pair.
 void putAll(Map map)
          Adds all elements from the specified Map.
 Object remove(Object key)
          Removes the mapping for the specified key.
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

OrderedHashMap

public OrderedHashMap()
Instantiates an empty OrderedHashMap.


OrderedHashMap

public OrderedHashMap(int capacity)
Instantiates an empty OrderedHashMap with the specified capacity.

Parameters:
capacity - the initial capacity

OrderedHashMap

public OrderedHashMap(int capacity,
                      float load_factor)
Instantiates an empty OrderedHashMap with the specified capacity and load factor.

Parameters:
capacity - the initial capacity
load_factor - the load factor

OrderedHashMap

public OrderedHashMap(Map map)
Instantiates an OrderedHashMap from an existing Map.

Parameters:
map - the map
Method Detail

put

public Object put(Object key,
                  Object value)
Adds a key/value pair.

Specified by:
put in interface Map
Overrides:
put in class HashMap
Parameters:
key - the key
value - the value
Returns:
Object

putAll

public void putAll(Map map)
Adds all elements from the specified Map.

Specified by:
putAll in interface Map
Overrides:
putAll in class HashMap
Parameters:
map - the Map

getKey

public Object getKey(int index)
Returns the Object key for a specified index.

Parameters:
index - an index into the ordered list
Returns:
the key as an Object

getValue

public Object getValue(int index)
Returns the Object value for a specified index.

Parameters:
index - an index into the ordered list
Returns:
the value as an Object

remove

public Object remove(Object key)
Removes the mapping for the specified key.

Specified by:
remove in interface Map
Overrides:
remove in class HashMap
Parameters:
key - the key
Returns:
the mapping

clear

public void clear()
Clears the map.

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

orderedKeySet

public List orderedKeySet()
Returns the key set as an ordered List.

Returns:
the key set as an ordered List


Copyright ©2005