|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.Dictionary org.w3c.util.ArrayDictionary
public class ArrayDictionary
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 !
Field Summary | |
---|---|
protected int |
incr
By how much to grow |
protected java.lang.Object[] |
keys
The array of keys |
protected int |
nelems
How many real elements are in |
protected java.lang.Object[] |
values
The array of corresponding values |
Constructor Summary | |
---|---|
ArrayDictionary()
Create an ArrayDictionary using default values for initial size and increment. |
|
ArrayDictionary(int init)
Create an ArrayDictionary using the given initial size. |
|
ArrayDictionary(int init,
int incr)
Create an ArrayDictionary using the given initial size and the given increment for growing the array. |
|
ArrayDictionary(java.lang.Object[] keys,
java.lang.Object[] values)
Create an ArrayDicitonary, using (not copying) the given pair of arrays as keys and values. |
|
ArrayDictionary(java.lang.Object[] keys,
java.lang.Object[] values,
int incr)
Create an ArrayDicitonary, using (not copying) the given pair of arrays as keys and values. |
|
ArrayDictionary(java.util.Vector keys,
java.util.Vector values)
Create an ArrayDictionary, contructing the arrays of keys and values from the two given vectors. |
|
ArrayDictionary(java.util.Vector keys,
java.util.Vector values,
int incr)
Create an ArrayDictionary, contructing the arrays of keys and values from the two given vectors. |
Method Summary | |
---|---|
int |
capacity()
Returns the maximum number of keys the dictionary can hold without reallocating an array. |
java.lang.Object |
clone()
Clone this array dictionary. |
java.lang.Object |
elementAt(int n)
Returns the nth element (value). |
java.util.Enumeration |
elements()
Returns an enumeration of the elements of the dictionary. |
void |
ensureCapacity(int minCapacity)
Increases the capacity of this dictionary to at least the specified number of key/value mappings. |
java.lang.Object |
get(java.lang.Object key)
Returns the value that maps to the given key. |
java.lang.Object[] |
getMany(java.lang.Object[] rKeys)
"Optimized" method to obtain the values corresponding to several keys, in one swoop. |
protected void |
grow()
|
protected void |
grow(int newCapacity)
|
boolean |
isEmpty()
Are there any entries in the dictionary? |
java.lang.Object |
keyAt(int n)
Returns the nth key. |
java.util.Enumeration |
keys()
Returns an enumeration of the keys of the dictionary. |
static void |
main(java.lang.String[] args)
A kludge for testing ArrayDictionary |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Adds a mapping between a key and a value to the dictionary. |
java.lang.Object |
remove(java.lang.Object key)
Removes a key (and its value) from the dictionary; |
java.lang.Object |
removeElementAt(int n)
Removes the nth mapping (key/value pair) in the dictionary. |
java.lang.Object |
setElementAt(int n,
java.lang.Object newVal)
Sets the element at the nth place in the array. |
int |
size()
Returns the number of elements in the dictionary |
java.lang.String |
toString()
Creates a string representation of the dictionary |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.lang.Object[] keys
protected java.lang.Object[] values
protected int nelems
protected int incr
Constructor Detail |
---|
public ArrayDictionary()
public ArrayDictionary(int init)
init
- The initial sizepublic ArrayDictionary(int init, int incr)
init
- the initial sizeincr
- the incrementpublic ArrayDictionary(java.util.Vector keys, java.util.Vector values)
keys
- the vector of keysvalues
- the vector of valuespublic ArrayDictionary(java.util.Vector keys, java.util.Vector values, int incr)
keys
- the vector of keysvalues
- the vector of valuesincr
- the increment for growing the arrayspublic ArrayDictionary(java.lang.Object[] keys, java.lang.Object[] values)
keys
- the array of keysvalues
- the array of valuespublic ArrayDictionary(java.lang.Object[] keys, java.lang.Object[] values, int incr)
keys
- the array of keysvalues
- the array of valuesincr
- the increment for growing the arraysMethod Detail |
---|
public java.lang.Object clone()
As for hashtables, a shallow copy is made, the keys and elements themselves are not cloned.
clone
in class java.lang.Object
protected final void grow()
protected void grow(int newCapacity)
public java.util.Enumeration elements()
elements
in class java.util.Dictionary
public java.lang.Object get(java.lang.Object key)
get
in class java.util.Dictionary
key
- the key
public java.lang.Object[] getMany(java.lang.Object[] rKeys)
rKeys
- An array of requested keys
public final boolean isEmpty()
isEmpty
in class java.util.Dictionary
public final void ensureCapacity(int minCapacity)
minCapacity
- the desired minimum capacitypublic java.util.Enumeration keys()
keys
in class java.util.Dictionary
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in class java.util.Dictionary
key
- the keyvalue
- the corresponding value
public java.lang.Object remove(java.lang.Object key)
remove
in class java.util.Dictionary
key
- the key to remove
public final int size()
size
in class java.util.Dictionary
public final int capacity()
public final java.lang.Object keyAt(int n)
n
- the index of the desired key
public final java.lang.Object elementAt(int n)
n
- the index of the desired element
public java.lang.Object setElementAt(int n, java.lang.Object newVal)
n
- the index of the element to changenewVal
- the value to change it to
public java.lang.Object removeElementAt(int n)
n
- the index of the element to remove
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |