OpMath

com.opmath.util.datastruct
Class OrderedHashtable

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--java.util.Hashtable
              |
              +--com.opmath.util.datastruct.OrderedHashtable
All Implemented Interfaces:
Cloneable, Map, Serializable
Direct Known Subclasses:
LCHashtable, UCHashtable

public class OrderedHashtable
extends Hashtable

A functional extension to java.util.Hashtable.

OrderedHashtable is a utility class, providing specialized Hashtable semantics.

The class extends Hashtable so as to to retain the order in which entries were added to the table. The OrderedHashtable's data storage is provided by a java.util.Hashtable. Thus, OrderedHashtable retains the efficiency of its superclass.

OrderedHashtable also provides for normalization of its keys. All methods which use a key preprocess their key value using the protected method normalized(Object). In the case of OrderedHashtable, normalized(Object) is a null method - the key argument is returned 'as is'. However, any subclass of OrderedHashtable is free to specialise normalized(Object) in any way.

Copyright: (c) 2002 The Open Math Company Limited

The Terms of Distribution of this software are stipulated in the javadoc Overview for this project.

Since:
J2SE 1.3
Version:
utilities-v011
Author:
Bruno Beloff bruno.beloff@opmath.com
See Also:
Serialized Form

Constructor Summary
OrderedHashtable()
          Constructs a new OrderedHashtable instance.
OrderedHashtable(ComparableList newKeys)
          Constructs a new OrderedHashtable instance.
OrderedHashtable(String[] newStrKeys)
          Constructs a new OrderedHashtable instance.
 
Method Summary
 boolean containsKey(Object key)
          Tests whether the key is known to the receiving container.
 Enumeration elements()
          returns an enumeration of the values in this OrderedHashtable instance.
 Object get(Object key)
           
 Enumeration keys()
          Returns an enumeration of the keys in this OrderedHashtable instance.
protected  Object normalized(Object key)
          The skeleton normalization method.
 Object put(Object key, Object value)
          Maps the specified key to the specified value in this OrderedHashtable.
 void putAll(Map t)
          Copies all of the mappings from the specified Map to this OrderedHashtable These mappings will replace any mappings that this OrderedHashtable had for any of the keys currently in the specified Map.
 Object remove(Object key)
          Removes the key (and its corresponding value) from this OrderedHashtable .
 String toString()
          Returns a new String, detailing the contents of this OrderedHashtable instance.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsValue, entrySet, equals, hashCode, isEmpty, keySet, rehash, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrderedHashtable

public OrderedHashtable()
Constructs a new OrderedHashtable instance. Its entries will be added later.

Since:
J2SE 1.3

OrderedHashtable

public OrderedHashtable(ComparableList newKeys)
Constructs a new OrderedHashtable instance. Its entries are identified by keys contained in the ComparableList.

NOTE: Multiple instances of the same key are discarded.

Parameters:
newKeys - the ComparableList supplying the keys.
Since:
J2SE 1.3

OrderedHashtable

public OrderedHashtable(String[] newStrKeys)
Constructs a new OrderedHashtable instance. The entries are identified by keys contained in the String array.

NOTE: Multiple instances of the same key are discarded.

Parameters:
newStrKeys - the String[] supplying the keys.
Since:
J2SE 1.3
Method Detail

normalized

protected Object normalized(Object key)
The skeleton normalization method. This method does not alter the value of the key; it simply provides a template for specialized versions of the method belonging to subclasses of OrderedHashtable.

Parameters:
key - the Object key to be normalized.
Returns:
the normalized key.
Since:
J2SE 1.3

keys

public Enumeration keys()
Returns an enumeration of the keys in this OrderedHashtable instance. Use the Enumeration methods on the returned object to fetch the keys sequentially.

Overrides:
keys in class Hashtable
Returns:
an Enumeration of the values in this hashtable.
Since:
J2SE 1.3
See Also:
Enumeration

elements

public Enumeration elements()
returns an enumeration of the values in this OrderedHashtable instance. Use the Enumeration methods on the returned object to fetch the elements sequentially.

Overrides:
elements in class Hashtable
Returns:
an Enumeration of the values in this hashtable.
Since:
J2SE 1.3
See Also:
Enumeration

put

public Object put(Object key,
                  Object value)
           throws NullPointerException
Maps the specified key to the specified value in this OrderedHashtable. 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.

Specified by:
put in interface Map
Overrides:
put in class Hashtable
Parameters:
key - the OrderedHashtable key.
value - the value.
Returns:
the previous value of the specified key in this OrderedHashtable, or null if it did not have one.
Throws:
NullPointerException - An exception thrown if the key or value is null.
Since:
J2SE 1.3

get

public Object get(Object key)
Specified by:
get in interface Map
Overrides:
get in class Hashtable

putAll

public void putAll(Map t)
Copies all of the mappings from the specified Map to this OrderedHashtable These mappings will replace any mappings that this OrderedHashtable had for any of the keys currently in the specified Map.

Specified by:
putAll in interface Map
Overrides:
putAll in class Hashtable
Parameters:
t - the mapping of new key-value pairs.
Since:
J2SE 1.3

remove

public Object remove(Object key)
              throws NullPointerException
Removes the key (and its corresponding value) from this OrderedHashtable . remove(Object) does nothing if the key is not in the OrderedHashtable instance.

Specified by:
remove in interface Map
Overrides:
remove in class Hashtable
Parameters:
key - the OrderedHashtable key.
Returns:
the value to which the key had been mapped in this OrderedHashtable, or null if the key did not have a mapping.
Throws:
NullPointerException - An exception thrown if the key or value is null.
Since:
J2SE 1.3

containsKey

public boolean containsKey(Object key)
Tests whether the key is known to the receiving container.

Prior to the test, the key is normalized according to the normalized(Object) method. In the case of OrderedHashtable, the normalized(Object) method does nothing. However, subclasses of OrderedHashtable may have other normalized(Object) methods.

Specified by:
containsKey in interface Map
Overrides:
containsKey in class Hashtable
Returns:
a String.
Since:
J2SE 1.3

toString

public String toString()
Returns a new String, detailing the contents of this OrderedHashtable instance.

Overrides:
toString in class Hashtable
Returns:
a String.
Since:
J2SE 1.3

OpMath

Submit a bug or feature to Open Math
Copyright © 2002 Open Math Company Limited, Brighton, UK