com.ibm.dse.tools.workbench.base
Class OrderedHashtable

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--com.ibm.dse.tools.workbench.base.OrderedHashtable

public class OrderedHashtable
extends java.util.Hashtable

This class implements an ordered hashtable, which maps keys to values and is able to reorder the entries by access time. The entries will be reordered every time an entry is accessed or inserted.

See Also:
Serialized Form

Inner Class Summary
static class OrderedHashtable.Entry
          Hashtable collision list.
 
Constructor Summary
OrderedHashtable()
          Constructs a new, empty ordered hashtable with a default capacity and load factor, which is 0.75.
OrderedHashtable(int initialCapacity)
          Constructs a new, empty ordered hashtable with the specified initial capacity and default load factor, which is 0.75.
OrderedHashtable(int initialCapacity, float loadFactor)
          Constructs a new, empty hashtable with the specified initial capacity, the specified load factor, the maximum capacity and the unloadFactor.
OrderedHashtable(int initialCapacity, float loadFactor, int maxCapacity, float unloadFactor)
          Constructs a new, empty ordered hashtable with the specified initial capacity, the specified load factor, the maximum capacity and the unloadFactor.
OrderedHashtable(java.util.Map t)
          Constructs a new ordered hashtable with the same mappings as the given Map.
 
Method Summary
 void clear()
          Clears this ordered hashtable so that it contains no keys.
 java.lang.Object clone()
          Creates a shallow copy of this ordered hashtable.
 boolean contains(java.lang.Object value)
          Tests if some key maps into the specified value in this ordered hashtable.
 boolean containsKey(java.lang.Object key)
          Tests if the specified object is a key in this ordered hashtable.
 boolean containsValue(java.lang.Object value)
          Returns true if this Hashtable maps one or more keys to this value.
 java.util.Enumeration elements()
          Returns an enumeration of the values in this ordered hashtable.
 java.util.Set entrySet()
          Returns a Set view of the entries contained in this Hashtable.
 boolean equals(java.lang.Object o)
          Compares the specified Object with this Map for equality, as per the definition in the Map interface.
 java.lang.Object get(java.lang.Object key)
          Returns the value to which the specified key is mapped in this hashtable.
 int hashCode()
          Returns the hash code value for this Map as per the definition in the Map interface.
 boolean isEmpty()
          Tests if this hashtable maps no keys to values.
 java.util.Enumeration keys()
          Returns an enumeration of the keys in this hashtable.
 java.util.Set keySet()
          Returns a Set view of the keys contained in this ordered Hashtable.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Maps the specified key to the specified value in this ordered hashtable.
 void putAll(java.util.Map t)
          Copies all of the mappings from the specified Map to this Hashtable These mappings will replace any mappings that this Hashtable had for any of the keys currently in the specified Map.
protected  void rehash()
          Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently.
 java.lang.Object remove(java.lang.Object key)
          Removes the key (and its corresponding value) from this ordered hashtable.
 int size()
          Returns the number of keys in this ordered hashtable.
 java.lang.String toString()
          Returns a string representation of this Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters "" (comma and space).
 java.util.Collection values()
          Returns a Collection view of the values contained in this ordered Hashtable.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrderedHashtable

public OrderedHashtable()
Constructs a new, empty ordered hashtable with a default capacity and load factor, which is 0.75.

OrderedHashtable

public OrderedHashtable(int initialCapacity)
Constructs a new, empty ordered hashtable with the specified initial capacity and default load factor, which is 0.75.
Parameters:
initialCapacity - int the initial capacity of the hashtable.

OrderedHashtable

public OrderedHashtable(int initialCapacity,
                        float loadFactor)
Constructs a new, empty hashtable with the specified initial capacity, the specified load factor, the maximum capacity and the unloadFactor.
Parameters:
initialCapacity - int the initial capacity of the hashtable.
loadFactor - float the load factor of the hashtable.

OrderedHashtable

public OrderedHashtable(int initialCapacity,
                        float loadFactor,
                        int maxCapacity,
                        float unloadFactor)
Constructs a new, empty ordered hashtable with the specified initial capacity, the specified load factor, the maximum capacity and the unloadFactor.
Parameters:
initialCapacity - int the initial capacity of the hashtable.
loadFactor - float the load factor of the hashtable.
maxCapacity - int the initial capacity of the hashtable.
unloadFactor - float the load factor of the hashtable.
Throws:
java.lang.IllegalArgumentException - if the initial capacity is less than zero, or if the load factor is nonpositive.

OrderedHashtable

public OrderedHashtable(java.util.Map t)
Constructs a new ordered hashtable with the same mappings as the given Map. The hashtable is created with a capacity of twice the number of entries in the given Map or 11 (whichever is greater), and a default load factor, which is 0.75.
Parameters:
t - java.util.Map
Method Detail

clear

public void clear()
Clears this ordered hashtable so that it contains no keys.
Overrides:
clear in class java.util.Hashtable

clone

public java.lang.Object clone()
Creates a shallow copy of this ordered hashtable. All the structure of the hashtable itself is copied, but the keys and values are not cloned. This is a relatively expensive operation.
Overrides:
clone in class java.util.Hashtable
Returns:
java.lang.Object a clone of the hashtable.

contains

public boolean contains(java.lang.Object value)
Tests if some key maps into the specified value in this ordered hashtable. This operation is more expensive than the containsKey method.

Note that this method is identical in functionality to containsValue, (which is part of the Map interface in the collections framework).

Overrides:
contains in class java.util.Hashtable
Parameters:
value - java.lang.Object value a value to search for.
Returns:
boolean true if and only if some key maps to the value argument in this hashtable as determined by the equals method; false otherwise.

containsKey

public boolean containsKey(java.lang.Object key)
Tests if the specified object is a key in this ordered hashtable.
Overrides:
containsKey in class java.util.Hashtable
Parameters:
key - java.lang.Object possible key.
Returns:
boolean true if and only if the specified object is a key in this hashtable, as determined by the equals method; false otherwise.

containsValue

public boolean containsValue(java.lang.Object value)
Returns true if this Hashtable maps one or more keys to this value.

Note that this method is identical in functionality to contains (which predates the Map interface).

Overrides:
containsValue in class java.util.Hashtable
Parameters:
value - java.lang.Object value whose presence in this Hashtable is to be tested.
Returns:
boolean

elements

public java.util.Enumeration elements()
Returns an enumeration of the values in this ordered hashtable. Use the Enumeration methods on the returned object to fetch the elements sequentially.
Overrides:
elements in class java.util.Hashtable
Returns:
java.util.Enumeration an enumeration of the values in this hashtable.

entrySet

public java.util.Set entrySet()
Returns a Set view of the entries contained in this Hashtable. Each element in this collection is a Map.Entry. The Set is backed by the Hashtable, so changes to the Hashtable are reflected in the Set, and vice-versa. The Set supports element removal (which removes the corresponding entry from the Hashtable), but not element addition.
Overrides:
entrySet in class java.util.Hashtable
Returns:
java.util.Set

equals

public boolean equals(java.lang.Object o)
Compares the specified Object with this Map for equality, as per the definition in the Map interface.
Overrides:
equals in class java.util.Hashtable
Returns:
boolean true if the specified Object is equal to this Map.

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which the specified key is mapped in this hashtable.
Overrides:
get in class java.util.Hashtable
Parameters:
key - java.lang.Object a key in the hashtable.
Returns:
java.lang.Object the value to which the key is mapped in this hashtable; null if the key is not mapped to any value in this hashtable.

hashCode

public int hashCode()
Returns the hash code value for this Map as per the definition in the Map interface.
Overrides:
hashCode in class java.util.Hashtable
Returns:
int

isEmpty

public boolean isEmpty()
Tests if this hashtable maps no keys to values.
Overrides:
isEmpty in class java.util.Hashtable
Returns:
boolean true if this ordered hashtable maps no keys to values; false otherwise.

keys

public java.util.Enumeration keys()
Returns an enumeration of the keys in this hashtable.
Overrides:
keys in class java.util.Hashtable
Returns:
java.util.Enumeration an enumeration of the keys in this hashtable.

keySet

public java.util.Set keySet()
Returns a Set view of the keys contained in this ordered Hashtable. The Set is backed by the ordered Hashtable, so changes to the ordered Hashtable are reflected in the Set, and vice-versa. The Set supports element removal (which removes the corresponding entry from the ordered Hashtable), but not element addition.
Overrides:
keySet in class java.util.Hashtable
Returns:
java.util.Set

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Maps the specified key to the specified value in this ordered 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.

Overrides:
put in class java.util.Hashtable
Parameters:
key - java.lang.Object the hashtable key.
value - java.lang.Object the value.
Returns:
java.lang.Object the previous value of the specified key in this ordered hashtable, or null if it did not have one.
Throws:
NullPointerException - if the key or value is null.

putAll

public void putAll(java.util.Map t)
Copies all of the mappings from the specified Map to this Hashtable These mappings will replace any mappings that this Hashtable had for any of the keys currently in the specified Map.
Overrides:
putAll in class java.util.Hashtable
Parameters:
t - java.util.Map

rehash

protected void rehash()
Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently. This method is called automatically when the number of keys in the hashtable exceeds this hashtable's capacity and load factor.
Overrides:
rehash in class java.util.Hashtable

remove

public java.lang.Object remove(java.lang.Object key)
Removes the key (and its corresponding value) from this ordered hashtable. This method does nothing if the key is not in the hashtable.
Overrides:
remove in class java.util.Hashtable
Parameters:
key - java.lang.Object the key that needs to be removed.
Returns:
java.lang.Object the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping.

size

public int size()
Returns the number of keys in this ordered hashtable.
Overrides:
size in class java.util.Hashtable
Returns:
int the number of keys in this ordered hashtable.

toString

public java.lang.String toString()
Returns a string representation of this Hashtable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters "" (comma and space). Each entry is rendered as the key, an equals sign =, and the associated element, where the toString method is used to convert the key and element to strings.

Overrides to toString method of Object.

Overrides:
toString in class java.util.Hashtable
Returns:
java.lang.String a string representation of this hashtable.

values

public java.util.Collection values()
Returns a Collection view of the values contained in this ordered Hashtable. The Collection is backed by the Hashtable, so changes to the Hashtable are reflected in the Collection, and vice-versa. The Collection supports element removal (which removes the corresponding entry from the Hashtable), but not element addition.
Overrides:
values in class java.util.Hashtable
Returns:
java.util.Collection