Class w3c.util.ArrayDictionary
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class w3c.util.ArrayDictionary

java.lang.Object
   |
   +----java.util.Dictionary
           |
           +----w3c.util.ArrayDictionary

public class ArrayDictionary
extends Dictionary
implements Cloneable
Random-access dictionary: like a dictionary but with a certain Vector-ness to it Besides all the methods from Dictionary, it also has methods that permit direct access to the nth element or nth key. Should be used with care...it's not too well tested yet, and it is very exposed.

This class does not provide thread-safeness, for the sake of efficiency, again it should be used with care !


Variable Index

 o incr
By how much to grow
 o keys
The array of keys
 o nelems
How many real elements are in
 o values
The array of corresponding values

Constructor Index

 o ArrayDictionary()
Create an ArrayDictionary using default values for initial size and increment.
 o ArrayDictionary(int)
Create an ArrayDictionary using the given initial size.
 o ArrayDictionary(int, int)
Create an ArrayDictionary using the given initial size and the given increment for growing the array.
 o ArrayDictionary(Object[], Object[])
Create an ArrayDicitonary, using (not copying) the given pair of arrays as keys and values.
 o ArrayDictionary(Object[], Object[], int)
Create an ArrayDicitonary, using (not copying) the given pair of arrays as keys and values.
 o ArrayDictionary(Vector, Vector)
Create an ArrayDictionary, contructing the arrays of keys and values from the two given vectors.
 o ArrayDictionary(Vector, Vector, int)
Create an ArrayDictionary, contructing the arrays of keys and values from the two given vectors.

Method Index

 o capacity()
Returns the maximum number of keys the dictionary can hold without reallocating an array.
 o clone()
Clone this array dictionary.
 o elementAt(int)
Returns the nth element (value).
 o elements()
Returns an enumeration of the elements of the dictionary.
 o ensureCapacity(int)
Increases the capacity of this dictionary to at least the specified number of key/value mappings.
 o get(Object)
Returns the value that maps to the given key.
 o getMany(Object[])
"Optimized" method to obtain the values corresponding to several keys, in one swoop.
 o grow()
 o grow(int)
 o isEmpty()
Are there any entries in the dictionary?
 o keyAt(int)
Returns the nth key.
 o keys()
Returns an enumeration of the keys of the dictionary.
 o main(String[])
A kludge for testing ArrayDictionary
 o put(Object, Object)
Adds a mapping between a key and a value to the dictionary.
 o remove(Object)
Removes a key (and its value) from the dictionary;
 o removeElementAt(int)
Removes the nth mapping (key/value pair) in the dictionary.
 o setElementAt(int, Object)
Sets the element at the nth place in the array.
 o size()
Returns the number of elements in the dictionary
 o toString()
Creates a string representation of the dictionary

Variables

 o keys
  protected Object keys[]
The array of keys
 o values
  protected Object values[]
The array of corresponding values
 o nelems
  protected int nelems
How many real elements are in
 o incr
  protected int incr
By how much to grow

Constructors

 o ArrayDictionary
  public ArrayDictionary()
Create an ArrayDictionary using default values for initial size and increment.
 o ArrayDictionary
  public ArrayDictionary(int init)
Create an ArrayDictionary using the given initial size. (The increment is set to the same value).
Parameters:
init - The initial size
 o ArrayDictionary
  public ArrayDictionary(int init,
                         int incr)
Create an ArrayDictionary using the given initial size and the given increment for growing the array.
Parameters:
init - the initial size
incr - the increment
 o ArrayDictionary
  public ArrayDictionary(Vector keys,
                         Vector values)
Create an ArrayDictionary, contructing the arrays of keys and values from the two given vectors. The two vectors should have the same size. The increment is set to the number of elements.
Parameters:
keys - the vector of keys
values - the vector of values
 o ArrayDictionary
  public ArrayDictionary(Vector keys,
                         Vector values,
                         int incr)
Create an ArrayDictionary, contructing the arrays of keys and values from the two given vectors. The two vectors should have the same size.
Parameters:
keys - the vector of keys
values - the vector of values
incr - the increment for growing the arrays
 o ArrayDictionary
  public ArrayDictionary(Object keys[],
                         Object values[])
Create an ArrayDicitonary, using (not copying) the given pair of arrays as keys and values. The increment is set to the length of the arrays.
Parameters:
keys - the array of keys
values - the array of values
 o ArrayDictionary
  public ArrayDictionary(Object keys[],
                         Object values[],
                         int incr)
Create an ArrayDicitonary, using (not copying) the given pair of arrays as keys and values.
Parameters:
keys - the array of keys
values - the array of values
incr - the increment for growing the arrays

Methods

 o clone
  public Object clone()
Clone this array dictionary.

As for hashtables, a shallow copy is made, the keys and elements themselves are not cloned.

Returns:
The clone.
Overrides:
clone in class Object
 o grow
  protected final void grow()
 o grow
  protected void grow(int newCapacity)
 o elements
  public Enumeration elements()
Returns an enumeration of the elements of the dictionary.
Returns:
the enumeration
Overrides:
elements in class Dictionary
 o get
  public Object get(Object key)
Returns the value that maps to the given key.
Parameters:
key - the key
Returns:
the value
Overrides:
get in class Dictionary
 o getMany
  public Object[] getMany(Object rKeys[])
"Optimized" method to obtain the values corresponding to several keys, in one swoop.
Parameters:
rKeys - An array of requested keys
Returns:
An array of corresponding values
 o isEmpty
  public final boolean isEmpty()
Are there any entries in the dictionary?
Returns:
true if there are no entries, false> otherwise.
Overrides:
isEmpty in class Dictionary
 o ensureCapacity
  public final void ensureCapacity(int minCapacity)
Increases the capacity of this dictionary to at least the specified number of key/value mappings.
Parameters:
minCapacity - the desired minimum capacity
 o keys
  public Enumeration keys()
Returns an enumeration of the keys of the dictionary.
Returns:
the enumeration
Overrides:
keys in class Dictionary
 o put
  public Object put(Object key,
                    Object value)
Adds a mapping between a key and a value to the dictionary. Will grow the arrays if necessary.
Parameters:
key - the key
value - the corresponding value
Returns:
the previous value corresponding to the key, or null if the key is new.
Overrides:
put in class Dictionary
 o remove
  public Object remove(Object key)
Removes a key (and its value) from the dictionary;
Parameters:
key - the key to remove
Returns:
the value that used to map to that key
Overrides:
remove in class Dictionary
 o size
  public final int size()
Returns the number of elements in the dictionary
Returns:
the number of elements
Overrides:
size in class Dictionary
 o capacity
  public final int capacity()
Returns the maximum number of keys the dictionary can hold without reallocating an array.
Returns:
the capacity of the dictionary
 o keyAt
  public final Object keyAt(int n)
Returns the nth key.
Parameters:
n - the index of the desired key
Returns:
the nth key, or null if no key in that place.
 o elementAt
  public final Object elementAt(int n)
Returns the nth element (value).
Parameters:
n - the index of the desired element
Returns:
the nth element, or null if no element in that place.
 o setElementAt
  public Object setElementAt(int n,
                             Object newVal)
Sets the element at the nth place in the array.
Parameters:
n - the index of the element to change
newVal - the value to change it to
Returns:
the old value
 o removeElementAt
  public Object removeElementAt(int n)
Removes the nth mapping (key/value pair) in the dictionary.
Parameters:
n - the index of the element to remove
Returns:
the old value of the element at the nth place
 o toString
  public String toString()
Creates a string representation of the dictionary
Returns:
the string representation.
Overrides:
toString in class Object
 o main
  public static void main(String args[])
A kludge for testing ArrayDictionary

All Packages  Class Hierarchy  This Package  Previous  Next  Index