| java.lang.Object java.util.Dictionary org.w3c.util.ArrayDictionary
ArrayDictionary | public class ArrayDictionary extends Dictionary implements Cloneable(Code) | | 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 !
author: Antonio Ramírez |
Constructor Summary | |
public | ArrayDictionary() Create an ArrayDictionary using default values for initial size and
increment. | public | ArrayDictionary(int init) Create an ArrayDictionary using the given initial size. | public | ArrayDictionary(int init, int incr) Create an ArrayDictionary using the given initial size and
the given increment for growing the array. | public | ArrayDictionary(Vector keys, Vector values) Create an ArrayDictionary, contructing the arrays of keys and
values from the two given vectors. | public | ArrayDictionary(Vector keys, Vector values, int incr) Create an ArrayDictionary, contructing the arrays of keys and
values from the two given vectors. | public | ArrayDictionary(Object[] keys, Object[] values) Create an ArrayDicitonary, using (not copying) the given pair
of arrays as keys and values. | public | ArrayDictionary(Object[] keys, Object[] values, int incr) Create an ArrayDicitonary, using (not copying) the given pair
of arrays as keys and values. |
Method Summary | |
final public int | capacity() Returns the maximum number of keys the dictionary can hold
without reallocating an array. | public Object | clone() Clone this array dictionary. | final public Object | elementAt(int n) Returns the nth element (value). | public Enumeration | elements() Returns an enumeration of the elements of the dictionary. | final public void | ensureCapacity(int minCapacity) Increases the capacity of this dictionary to at least the
specified number of key/value mappings. | public Object | get(Object key) Returns the value that maps to the given key. | public Object[] | getMany(Object[] rKeys) "Optimized" method to obtain the values
corresponding to several keys, in one swoop. | final protected void | grow() | protected void | grow(int newCapacity) | final public boolean | isEmpty() | final public Object | keyAt(int n) Returns the nth key. | public Enumeration | keys() Returns an enumeration of the keys of the dictionary. | public static void | main(String[] args) | public Object | put(Object key, Object value) Adds a mapping between a key and a value to the dictionary. | public Object | remove(Object key) | public Object | removeElementAt(int n) Removes the nth mapping (key/value pair) in the dictionary. | public Object | setElementAt(int n, Object newVal) Sets the element at the nth place in the array. | final public int | size() | public String | toString() |
incr | protected int incr(Code) | | By how much to grow
|
nelems | protected int nelems(Code) | | How many real elements are in
|
values | protected Object[] values(Code) | | The array of corresponding values
|
ArrayDictionary | public ArrayDictionary()(Code) | | Create an ArrayDictionary using default values for initial size and
increment.
|
ArrayDictionary | public ArrayDictionary(int init)(Code) | | 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)(Code) | | Create an ArrayDictionary using the given initial size and
the given increment for growing the array.
Parameters: init - the initial size Parameters: incr - the increment |
ArrayDictionary | public ArrayDictionary(Vector keys, Vector values)(Code) | | 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 Parameters: values - the vector of values |
ArrayDictionary | public ArrayDictionary(Vector keys, Vector values, int incr)(Code) | | 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 Parameters: values - the vector of values Parameters: incr - the increment for growing the arrays |
ArrayDictionary | public ArrayDictionary(Object[] keys, Object[] values)(Code) | | 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 Parameters: values - the array of values |
ArrayDictionary | public ArrayDictionary(Object[] keys, Object[] values, int incr)(Code) | | Create an ArrayDicitonary, using (not copying) the given pair
of arrays as keys and values.
Parameters: keys - the array of keys Parameters: values - the array of values Parameters: incr - the increment for growing the arrays |
capacity | final public int capacity()(Code) | | Returns the maximum number of keys the dictionary can hold
without reallocating an array.
the capacity of the dictionary |
clone | public Object clone()(Code) | | Clone this array dictionary.
As for hashtables, a shallow copy is made, the keys and elements
themselves are not cloned.
The clone. |
elementAt | final public Object elementAt(int n)(Code) | | Returns the nth element (value).
Parameters: n - the index of the desired element the nth element, or null if no element in that place. |
elements | public Enumeration elements()(Code) | | Returns an enumeration of the elements of the dictionary.
the enumeration |
ensureCapacity | final public void ensureCapacity(int minCapacity)(Code) | | Increases the capacity of this dictionary to at least the
specified number of key/value mappings.
Parameters: minCapacity - the desired minimum capacity |
get | public Object get(Object key)(Code) | | Returns the value that maps to the given key.
Parameters: key - the key the value |
getMany | public Object[] getMany(Object[] rKeys)(Code) | | "Optimized" method to obtain the values
corresponding to several keys, in one swoop.
Parameters: rKeys - An array of requested keys An array of corresponding values |
grow | final protected void grow()(Code) | | |
grow | protected void grow(int newCapacity)(Code) | | |
isEmpty | final public boolean isEmpty()(Code) | | Are there any entries in the dictionary?
true if there are no entries,false> otherwise. |
keyAt | final public Object keyAt(int n)(Code) | | Returns the nth key.
Parameters: n - the index of the desired key the nth key, or null if no key in that place. |
keys | public Enumeration keys()(Code) | | Returns an enumeration of the keys of the dictionary.
the enumeration |
main | public static void main(String[] args)(Code) | | A kludge for testing ArrayDictionary
|
put | public Object put(Object key, Object value)(Code) | | Adds a mapping between a key and a value to the dictionary.
Will grow the arrays if necessary.
Parameters: key - the key Parameters: value - the corresponding value the previous value corresponding to the key, or null ifthe key is new. |
remove | public Object remove(Object key)(Code) | | Removes a key (and its value) from the dictionary;
Parameters: key - the key to remove the value that used to map to that key |
removeElementAt | public Object removeElementAt(int n)(Code) | | Removes the nth mapping (key/value pair) in the dictionary.
Parameters: n - the index of the element to remove the old value of the element at the nth place |
setElementAt | public Object setElementAt(int n, Object newVal)(Code) | | Sets the element at the nth place in the array.
Parameters: n - the index of the element to change Parameters: newVal - the value to change it to the old value |
size | final public int size()(Code) | | Returns the number of elements in the dictionary
the number of elements |
toString | public String toString()(Code) | | Creates a string representation of the dictionary
the string representation. |
|
|