    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class org.w3c.util.ArrayDictionary

    java.lang.Object
       |
       +----java.util.Dictionary
               |
               +----org.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 !

##

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

##

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

##

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

##

keys

     protected Object keys[]

  The array of keys

values

     protected Object values[]

  The array of corresponding values

nelems

     protected int nelems

  How many real elements are in

incr

     protected int incr

  By how much to grow

##

ArrayDictionary

     public ArrayDictionary()

  Create an ArrayDictionary using default values for initial size and increment.

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

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

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

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

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

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

##

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

grow

     protected final void grow()

grow

     protected void grow(int newCapacity)

elements

     public Enumeration elements()

  Returns an enumeration of the elements of the dictionary.

  Returns:
    the enumeration
  Overrides:
    elements in class Dictionary

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

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

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

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

keys

     public Enumeration keys()

  Returns an enumeration of the keys of the dictionary.

  Returns:
    the enumeration
  Overrides:
    keys in class Dictionary

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

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

size

     public final int size()

  Returns the number of elements in the dictionary

  Returns:
    the number of elements
  Overrides:
    size in class Dictionary

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

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.

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.

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

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

toString

     public String toString()

  Creates a string representation of the dictionary

  Returns:
    the string representation.
  Overrides:
    toString in class Object

main

     public static void main(String args[])

  A kludge for testing ArrayDictionary

    All Packages  Class Hierarchy  This Package  Previous  Next  Index