cds.util
Class SortedHashtable

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended bycds.util.SortedHashtable
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class SortedHashtable
extends java.util.Hashtable

Hastable allowing to display the entries in a particular order. By default the same order as the elements were added to the table.
It is also possible to specify the position where the entry should be placed in the list.
This is obtained by managing a ArrayList of the keys. It is then possible to sort this list in any kind of order...

Version:
1.0 Apr 2002
1.1 Jun 2002 add a replace() method
Author:
Marc Wenger/CDS
See Also:
Serialized Form

Nested Class Summary
(package private)  class SortedHashtable.Iter
          Inner class for creating an iterator on the SortedHashtable elements
 
Nested classes inherited from class java.util.Hashtable
 
Field Summary
(package private)  java.util.ArrayList keys
           
 
Fields inherited from class java.util.Hashtable
 
Constructor Summary
SortedHashtable()
          Basic Constructor
SortedHashtable(int inisize)
          Constructor specifying an initial table size
 
Method Summary
 void add(java.lang.Object key, int pos, java.lang.Object data)
          Add a new object with its key at a specified position
The object will be added to the current list a the defined position.
 void add(java.lang.Object key, java.lang.Object data)
          Add an object with its key.
 void clear()
          Empties the Sorted Hashtable
 java.lang.Object get(int num)
          Gets an entry specified by its rank number
 java.util.Iterator iterator()
          Returns an iterator on the objects.
 java.util.Iterator keyIterator()
          Returns an iterator to browse through the list of object keys in the order they were entered or explicitely placed.
 java.lang.Object replace(java.lang.Object key, java.lang.Object data)
          Replaces the value of an existing entry in the SortedHashtable
The new data will replace the old one, which will be returned.
 java.lang.Object[] toArray()
          Returns the list of object keys as an array
 java.lang.Object[] toArray(java.lang.Object[] o)
          Returns the list of objects keys as an array of the specified type
 java.lang.Object[] toSortedArray()
          Returns a sorted list of the item values in the hashtable
 
Methods inherited from class java.util.Hashtable
clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

keys

java.util.ArrayList keys
Constructor Detail

SortedHashtable

public SortedHashtable()
Basic Constructor


SortedHashtable

public SortedHashtable(int inisize)
Constructor specifying an initial table size

Parameters:
inisize - initial table size
Method Detail

add

public void add(java.lang.Object key,
                java.lang.Object data)
         throws ExistenceException
Add an object with its key.
The object will be appended to the current object list, and may be retrieved either by its key, or in sequence through the list.

Parameters:
key - key allowing to retrieve the object through the Hashtable
data - object to add in the table
Throws:
ExistenceException

add

public void add(java.lang.Object key,
                int pos,
                java.lang.Object data)
         throws ExistenceException
Add a new object with its key at a specified position
The object will be added to the current list a the defined position. This position can be higher than the initial size or the current size of the list. The needed size adjustement are made automatically.

Parameters:
key - key allowing to retrieve the object through the Hashtable
pos - the position in the list where the object should be placed. If this place was already occupied, the new object will replace the old one.
data - object to add in the table
Throws:
ExistenceException

replace

public java.lang.Object replace(java.lang.Object key,
                                java.lang.Object data)
Replaces the value of an existing entry in the SortedHashtable
The new data will replace the old one, which will be returned. As the key doesn't change, the position of the object in the sorted list remains the same.
If the object is not yet in the table, it is NOT added.

Parameters:
key - key of an existing object which value is replaced
data - new data object to associate with the key
Returns:
the previous object (or null if it does not yet exist)

iterator

public java.util.Iterator iterator()
Returns an iterator on the objects. They will be returned in the order they were entered or explicitely placed.


keyIterator

public java.util.Iterator keyIterator()
Returns an iterator to browse through the list of object keys in the order they were entered or explicitely placed.


toSortedArray

public java.lang.Object[] toSortedArray()
Returns a sorted list of the item values in the hashtable

Returns:
an array of sorted objects

clear

public void clear()
Empties the Sorted Hashtable


get

public java.lang.Object get(int num)
Gets an entry specified by its rank number

Parameters:
num - number of the entry

toArray

public java.lang.Object[] toArray()
Returns the list of object keys as an array

Returns:
an array of objects

toArray

public java.lang.Object[] toArray(java.lang.Object[] o)
Returns the list of objects keys as an array of the specified type

Returns:
an array of object of a defined type