com.sibvisions.util
Class OrderedHashtable<K,V>

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable<K,V>
          extended by com.sibvisions.util.OrderedHashtable<K,V>
Type Parameters:
K - the key object type
V - the value object type
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>

public class OrderedHashtable<K,V>
extends Hashtable<K,V>

The OrderedHashtable extends a Hashtable and keeps the add order. It works according to the FiFo principle. The first key added is the first key in the key list.

See Also:
Hashtable, Serialized Form

Constructor Summary
OrderedHashtable()
          Creates a new instance of OrderedHashtable with a default initial capacity (11) and load factor (0.75).
OrderedHashtable(int pCapacity)
          Creates a new instance of OrderedHashtable with the specified initial capacity and default load factor (0.75).
OrderedHashtable(int pCapacity, float pLoadFactor)
          Creates a new instance of OrderedHashtable with the specified initial capacity and the specified load factor.
OrderedHashtable(Map<? extends K,? extends V> pMap)
          Creates a new instance of OrderedHashtable with the same mappings as the given Map.
 
Method Summary
 void clear()
          
 Object clone()
          Creates a shallow copy of this hashtable.
 K getKey(int pIndex)
          Gets a key by index.
 Enumeration<K> keys()
          Returns an enumeration of the keys in this hashtable.
 V put(K pKey, V pValue)
          Maps the specified pKey to the specified pValue in this hashtable.
 V remove(Object pKey)
          Removes the key (and its corresponding value) from this hashtable.
 
Methods inherited from class java.util.Hashtable
contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keySet, putAll, rehash, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrderedHashtable

public OrderedHashtable()
Creates a new instance of OrderedHashtable with a default initial capacity (11) and load factor (0.75).

See Also:
Hashtable.Hashtable()

OrderedHashtable

public OrderedHashtable(int pCapacity)
Creates a new instance of OrderedHashtable with the specified initial capacity and default load factor (0.75).

Parameters:
pCapacity - the initial capacity of the hashtable
Throws:
IllegalArgumentException - if the initial capacity is less than zero
See Also:
Hashtable.Hashtable(int)

OrderedHashtable

public OrderedHashtable(int pCapacity,
                        float pLoadFactor)
Creates a new instance of OrderedHashtable with the specified initial capacity and the specified load factor.

Parameters:
pCapacity - the initial capacity of the hashtable
pLoadFactor - the load factor of the hashtable
Throws:
IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive.
See Also:
Hashtable.Hashtable(int, float)

OrderedHashtable

public OrderedHashtable(Map<? extends K,? extends V> pMap)
Creates a new instance of OrderedHashtable with the same mappings as the given Map. The hashtable is created with an initial capacity sufficient to hold the mappings in the given Map and a default load factor (0.75).

Parameters:
pMap - the map whose mappings are to be placed in this map.
Throws:
NullPointerException - if the specified map is null.
Method Detail

put

public V put(K pKey,
             V pValue)
Maps the specified pKey to the specified pValue in this hashtable. Neither the key nor the value can be null.

The value can be retrieved by calling the get method with a key that is equal to the original key.

The order will be stored to guarantee the FiFo principle.

Specified by:
put in interface Map<K,V>
Overrides:
put in class Hashtable<K,V>
Parameters:
pKey - the hashtable key
pValue - the value
Returns:
the previous value of the specified key in this hashtable, or null if it did not have one
Throws:
NullPointerException - if the key or value is null
See Also:
Hashtable.get(Object)

remove

public V remove(Object pKey)
Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is not in the hashtable.

Specified by:
remove in interface Map<K,V>
Overrides:
remove in class Hashtable<K,V>
Parameters:
pKey - the key that needs to be removed
Returns:
the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping
Throws:
NullPointerException - if the key is null

clone

public Object clone()
Creates a shallow copy of this hashtable. All the structure of the hashtable itself is copied, but the keys and values are not cloned.

Overrides:
clone in class Hashtable<K,V>
Returns:
a clone of the hashtable

clear

public void clear()

Specified by:
clear in interface Map<K,V>
Overrides:
clear in class Hashtable<K,V>

keys

public Enumeration<K> keys()
Returns an enumeration of the keys in this hashtable. It is guaranteed that the order is the same as the keys have been added (FiFo principle).

Overrides:
keys in class Hashtable<K,V>
Returns:
an enumeration of the keys in this hashtable

getKey

public K getKey(int pIndex)
Gets a key by index.

Parameters:
pIndex - the index of the key
Returns:
the key
Throws:
ArrayIndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.