org.w3c.util
Class LookupTable

java.lang.Object
  extended by org.w3c.util.LookupTable
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class LookupTable
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

A kind of hashtable (maps keys to values), useful for a limited number of elements.

See Also:
Serialized Form

Field Summary
static int DEFAULT_CAPACITY
          The default capacity.
 
Constructor Summary
LookupTable()
          Constructor, build a LookupTable with a initial capacity set to DEFAULT_CAPACITY.
LookupTable(int capacity)
          Constructor.
 
Method Summary
 void clear()
          Clears this lookuptable so that it contains no keys.
 java.lang.Object clone()
          Creates a shallow copy of this lookuptable.
 boolean contains(java.lang.Object value)
          Tests if some key maps into the specified value in this lookuptable.
 boolean containsKey(java.lang.Object key)
          Tests if the specified object is a key in this lookuptable.
 java.util.Enumeration elements()
          Returns an enumeration of the values in this lookuptable.
 java.lang.Object get(java.lang.Object key)
          Returns the value to which the specified key is mapped in this lookuptable.
protected  void grow()
          Increases the capacity.
 boolean isEmpty()
          Tests if this lookuptable maps no keys to values.
 java.util.Enumeration keys()
          Returns an enumeration of the keys in this lookuptable.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Maps the specified key to the specified value in this lookuptable.
 java.lang.Object remove(java.lang.Object key)
          Removes the key (and its corresponding value) from this lookuptable.
 int size()
          Returns the number of keys in this lookuptable.
 java.lang.String toString()
          Returns a string representation of this Lookuptable object in the form of a set of entries, enclosed in braces and separated by the ASCII characters "" (comma and space).
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
The default capacity.

See Also:
Constant Field Values
Constructor Detail

LookupTable

public LookupTable(int capacity)
Constructor.

Parameters:
capacity - the initial capacity

LookupTable

public LookupTable()
Constructor, build a LookupTable with a initial capacity set to DEFAULT_CAPACITY.

Method Detail

size

public int size()
Returns the number of keys in this lookuptable.

Returns:
the number of keys in this lookuptable.

isEmpty

public boolean isEmpty()
Tests if this lookuptable maps no keys to values.

Returns:
true if this lookuptable maps no keys to values; false otherwise.

keys

public java.util.Enumeration keys()
Returns an enumeration of the keys in this lookuptable.

Returns:
an enumeration of the keys in this lookuptable.
See Also:
Enumeration, elements()

elements

public java.util.Enumeration elements()
Returns an enumeration of the values in this lookuptable. Use the Enumeration methods on the returned object to fetch the elements sequentially.

Returns:
an enumeration of the values in this lookuptable.
See Also:
Enumeration, keys()

contains

public boolean contains(java.lang.Object value)
Tests if some key maps into the specified value in this lookuptable.

Parameters:
value - a value to search for.
Returns:
true if and only if some key maps to the value argument in this lookuptable as determined by the equals method; false otherwise.
Throws:
java.lang.NullPointerException - if the value is null.
See Also:
containsKey(Object)

containsKey

public boolean containsKey(java.lang.Object key)
Tests if the specified object is a key in this lookuptable.

Parameters:
key - possible key.
Returns:
true if and only if the specified object is a key in this lookuptable, as determined by the equals method; false otherwise.
See Also:
contains(Object)

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which the specified key is mapped in this lookuptable.

Parameters:
key - a key in the lookuptable.
Returns:
the value to which the key is mapped in this lookuptable; null if the key is not mapped to any value in this lookuptable.
See Also:
put(Object, Object)

put

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

Parameters:
key - the lookuptable key.
value - the value.
Returns:
the previous value of the specified key in this lookuptable, or null if it did not have one.
Throws:
java.lang.NullPointerException - if the key or value is null.
See Also:
Object.equals(Object), get(Object)

grow

protected void grow()
Increases the capacity. This method is called automatically when the number of keys in the lookuptable exceeds this lookuptable's capacity.


remove

public java.lang.Object remove(java.lang.Object key)
Removes the key (and its corresponding value) from this lookuptable. This method does nothing if the key is not in the lookuptable.

Parameters:
key - the key that needs to be removed.
Returns:
the value to which the key had been mapped in this lookuptable, or null if the key did not have a mapping.

clear

public void clear()
Clears this lookuptable so that it contains no keys.


clone

public java.lang.Object clone()
Creates a shallow copy of this lookuptable. All the structure of the lookuptable itself is copied, but the keys and values are not cloned. This is a relatively expensive operation.

Overrides:
clone in class java.lang.Object
Returns:
a clone of the lookuptable.

toString

public java.lang.String toString()
Returns a string representation of this Lookuptable 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.lang.Object
Returns:
a string representation of this lookuptable.