ariba.util.core
Class OrderedHashtable

java.lang.Object
  extended by java.util.AbstractMap
      extended by ariba.util.core.Hashtable
          extended by ariba.util.core.OrderedHashtable
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.util.Map

public class OrderedHashtable
extends Hashtable

An OrderedHashtable is just like a normal Hashtable except that it remembers the order the keys were added to the table and, whenever keys() or elements() is called, they are returned in that order.

Just overrides all the appropriate methods in Hashtable.
Adds only one method reverseKeys(), which is the same as keys(), but the Enumeration is in the reverse order.

Note:: Because this an ordered collection, its performances maybe not be as good as an ordinary Hashtable. Use it only when the order of entry matters

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
OrderedHashtable()
           
 
Method Summary
 void clear()
          Removes all keys and elements from the Hashtable.
 java.lang.Object clone()
          Creates a shallow copy of the OrderedHashtable.
 java.util.Enumeration elements()
          Returns an Enumeration of the Hashtable's elements.
 int indexOfKey(java.lang.Object key)
           
 void insertElementAt(java.lang.Object key, java.lang.Object value, int index)
           
 java.util.Enumeration keys()
          Returns an Enumeration of the Hashtable's keys.
 java.util.Set keySet()
          Returns a Set view of the keys contained in this map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Places the key/element pair in the Hashtable.
 java.lang.Object remove(java.lang.Object key)
          Finds and removes key and the element associated with it from the Hashtable.
 int removeElement(java.lang.Object element)
          Finds and removes all occurrences of element from the Hashtable.
 java.lang.Object removeElementAt(int index)
           
 java.util.Enumeration reverseKeys()
           
 void setElementAt(java.lang.Object key, java.lang.Object value, int index)
          Set the element which is the key/value pair in this OrderedHashtable at a given index.
 java.util.Collection values()
          Returns a collection view of the values contained in this map.
 
Methods inherited from class ariba.util.core.Hashtable
contains, containsKey, count, elementsArray, elementsVector, entrySet, fromSerializedString, get, isEmpty, keysArray, keysVector, readExternal, size, toSerializedString, toString, toStringArray, writeExternal
 
Methods inherited from class java.util.AbstractMap
containsValue, equals, hashCode, putAll
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrderedHashtable

public OrderedHashtable()
Method Detail

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from class: Hashtable
Places the key/element pair in the Hashtable. If there is a key in the Hashtable matching key the corresponding element in the Hashtable is replaced by the specified element

Specified by:
put in interface java.util.Map
Overrides:
put in class Hashtable
Parameters:
key - the key to place into the Hashtable; may not be null
value - the element to place into the Hashtable; may not be null
Returns:
the element previously associated with the key if any, null otherwise.

clear

public void clear()
Description copied from class: Hashtable
Removes all keys and elements from the Hashtable.

Specified by:
clear in interface java.util.Map
Overrides:
clear in class Hashtable

remove

public java.lang.Object remove(java.lang.Object key)
Description copied from class: Hashtable
Finds and removes key and the element associated with it from the Hashtable.

Specified by:
remove in interface java.util.Map
Overrides:
remove in class Hashtable
Parameters:
key - the key to search the hashtable's keys for. Hashtable hashes and compares key using hashCode() and equals().
Returns:
the element associated with the key removed, or null if key was not present.

removeElement

public int removeElement(java.lang.Object element)
Description copied from class: Hashtable
Finds and removes all occurrences of element from the Hashtable. Note that this method is slow -- O(n) -- because it must scan the table searching for the element.

Overrides:
removeElement in class Hashtable
Parameters:
element - the element to search for. Hashtable compares elements using equals().
Returns:
the number of elements removed.
See Also:
MapUtil.removeElement(java.util.Map, java.lang.Object)

keys

public java.util.Enumeration keys()
Description copied from class: Hashtable
Returns an Enumeration of the Hashtable's keys.

Overrides:
keys in class Hashtable
Returns:
an enumeration of the keys in this Hashtable.
See Also:
Hashtable.keySet, Set.iterator(), Hashtable.elements()

elements

public java.util.Enumeration elements()
Description copied from class: Hashtable
Returns an Enumeration of the Hashtable's elements.

Overrides:
elements in class Hashtable
Returns:
an enumeration of the elements in this Hashtable.
See Also:
Hashtable.values, Collection.iterator(), Hashtable.keys()

clone

public java.lang.Object clone()
Creates a shallow copy of the OrderedHashtable. The table itself is cloned, but none of the keys or elements are copied.

Overrides:
clone in class Hashtable
Returns:
the cloned copy
Throws:
java.lang.InternalError - if the cloning operation fails.

keySet

public java.util.Set keySet()
Returns a Set view of the keys contained in this map. The Set is backed by the map, so changes to the map are reflected in the Set, and vice-versa. (If the map is modified while an iteration over the Set is in progress, the results of the iteration are undefined.) The Set supports element removal, which removes the corresponding entry from the map, via the Iterator.remove, Set.remove, removeAll retainAll, and clear operations. It does not support the add or addAll operations.

Specified by:
keySet in interface java.util.Map
Overrides:
keySet in class Hashtable
Returns:
a Set view of the keys contained in this map.

values

public java.util.Collection values()
Returns a collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. (If the map is modified while an iteration over the collection is in progress, the results of the iteration are undefined.) The collection supports element removal, which removes the corresponding entry from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Specified by:
values in interface java.util.Map
Overrides:
values in class Hashtable
Returns:
a collection view of the values contained in this map.

reverseKeys

public java.util.Enumeration reverseKeys()

insertElementAt

public void insertElementAt(java.lang.Object key,
                            java.lang.Object value,
                            int index)

setElementAt

public void setElementAt(java.lang.Object key,
                         java.lang.Object value,
                         int index)
Set the element which is the key/value pair in this OrderedHashtable at a given index. If the key (say A) corresponding to the given index (say B) is not the same as the input key argument, the key/value pair corrsponding to A is not removed from the hashtable. Instead the following takes place: (1) the key/value pair corresponding to B is updated in hashtable (that could mean a new key/value pair is added to the hashtable or that the value in B in the hashtable is replaced with the new value). (2) the key/value pair corresponding to B will be updated to be at position as specified by index. If key exists before but at a different order, this method will put key at position index, with the position of the other elements updated to fill in the original slot.

Parameters:
key - the key to be set
value - the value associated with key
index - the order of this key-value pair

removeElementAt

public java.lang.Object removeElementAt(int index)

indexOfKey

public int indexOfKey(java.lang.Object key)


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.