com.ls.util.container
Class ReferenceIdentityHashtable

java.lang.Object
  |
  +--com.ls.util.container.ReferenceIdentityHashtable

public class ReferenceIdentityHashtable
extends Object

ReferenceIdentityHashtable differs from class hashtable in two main topics:

  1. To compare keys, reference identity is used instead of equality checked with the equals() method.
  2. Time complexity is O(n) compared to O(0) of a hashtable since this class is based on Vectors for keys and values.
The first means that e.g. if there is two times an empty String to be stored, Hashtable will overwrite the first one when puting the second one, while this implementation keeps both references as keys and can distinguish them. This means that when looking up a value using a key, the SAME reference has to be passed to the get() method. As a wrong example:
If you call put(stringBuffer.toString()) you will never be able to retrieve the object by calling get(...), because you do not have a reference to the object. Calling get(stringBuffer.toString()) will NOT return a value, because toString() is creating a new object reference which is of course not stored as key.

Note:Access to objects of this class is not synchronized.

Version:
$Revision: 1.5 $
Author:
Last modified by $Author: TBerk $

Constructor Summary
ReferenceIdentityHashtable()
          Constructor to initialize the key/value container with the default capacity of a Vector (10)
ReferenceIdentityHashtable(int capacity)
          Constructor to initialize the key/value container with the capacity passed as argument.
 
Method Summary
 void clear()
          Removes all keys and values.
 boolean containsKey(Object key)
          Returns true, if the object reference passed is existing as key in the attribute container.
 boolean containsValue(Object key)
          Returns true, if the object reference passed is existing as value in the attribute container.
 Enumeration elements()
          Returns an enumeration of the values of this class.
 Object get(Object key)
          This function returns the attribute list of an object generated while parsing.
 boolean isEmpty()
          Returns true, if no key value pairs are contained.
 Iterator keyIterator()
          Returns an Iterator view on the stored keys.
 Enumeration keys()
          Returns an enumeration of the keys of this class.
 void put(Object key, Object value)
          Adds an object reference (representing a tag and used as key) and a list of attributes belonging to that tag.
 void remove(Object key)
          Removes the specified key and its value.
 int size()
          Returns the number of key/value mappings stored within this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReferenceIdentityHashtable

public ReferenceIdentityHashtable()
Constructor to initialize the key/value container with the default capacity of a Vector (10)

ReferenceIdentityHashtable

public ReferenceIdentityHashtable(int capacity)
Constructor to initialize the key/value container with the capacity passed as argument.
Parameters:
capacity - the number of key/value pairs the object can store initially
Method Detail

get

public Object get(Object key)
This function returns the attribute list of an object generated while parsing.
Parameters:
key - the object for which to get the attribute list
Returns:
attributeList containing all attributes of the tag represented by the passed object

put

public void put(Object key,
                Object value)
Adds an object reference (representing a tag and used as key) and a list of attributes belonging to that tag.
Parameters:
key - the object reference representing the xml tag
value - the list of attributes contained in the tag

containsKey

public boolean containsKey(Object key)
Returns true, if the object reference passed is existing as key in the attribute container. Equality is checked with == (reference identity, not equals())
Parameters:
key - the object reference used as key
Returns:
true, if the reference passed is contained as key

containsValue

public boolean containsValue(Object key)
Returns true, if the object reference passed is existing as value in the attribute container. Equality is checked with == (reference identity, not equals())
Parameters:
key - the object reference used as key
Returns:
true, if the reference passed is contained as value

isEmpty

public boolean isEmpty()
Returns true, if no key value pairs are contained.
Returns:
true, if no key value pairs are contained

clear

public void clear()
Removes all keys and values.

remove

public void remove(Object key)
Removes the specified key and its value.
Parameters:
key - the object reference (key) to be deleted

elements

public Enumeration elements()
Returns an enumeration of the values of this class.
Returns:
enumeration of the values of this class

keys

public Enumeration keys()
Returns an enumeration of the keys of this class.
Returns:
enumeration of the keys of this class

keyIterator

public Iterator keyIterator()
Returns an Iterator view on the stored keys.
Returns:
Iterator

size

public int size()
Returns the number of key/value mappings stored within this object.
Returns:
number of key/value mappings