|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Dictionary | +--oracle.bali.share.collection.ArrayMap
A Dictionary implementation that stores its contents in a single array. This approach is significantly faster for small sets of data than the use of a HashMap or Hashtable, though potentially much slower for very large sets.
ArrayMap is optimized for many-reads-few-write. In particular, it reallocates its array on any insertion or deletion.
ArrayMap also includes a series of static methods for managing the
Object array. These may be used in place of instantiating an
ArrayMap for clients that don't need a Dictionary implementation.
Clients using these methods must be careful to store the returned
Object array on any mutator method. They also must provide their
own synchronization, if needed. When using these static methods,
clients can opt to search for objects by identity (via
getByIdentity()
) instead of equality, while the static
get()
method will try identity before equality. This
latter approach is extremely fast but still safe for retrieval of
Strings that have all been interned, especially if misses are
infrequent (since misses do require a scan using Object.equals()).
It's worth remembering that String constants are always interned,
as required by the language specification.
Constructor Summary | |
ArrayMap()
Creates an empty ArrayMap, preallocating nothing. |
|
ArrayMap(java.util.Dictionary copy)
Creates an ArrayMap from another Dictionary. |
|
ArrayMap(int size)
Creates an ArrayMap, preallocating for a certain size. |
|
ArrayMap(int size,
int increment)
Creates an ArrayMap, preallocating for a certain size. |
Method Summary | |
boolean |
addAll(ArrayMap arrayMap)
Adds all elements from another ArrayMap into this map. |
void |
clear()
Removes all elements from the ArrayMap. |
java.lang.Object |
clone()
Clones the map. |
java.util.Enumeration |
elements()
Returns an enumeration of the values in this dictionary. |
boolean |
equals(java.lang.Object o)
Determines if this ArrayMap is equal to another object. |
java.lang.Object |
get(java.lang.Object key)
Returns the value to which the key is mapped in this dictionary. |
static java.lang.Object |
get(java.lang.Object[] array,
java.lang.Object key)
Gets the object stored with the given key. |
static java.lang.Object |
getByEquality(java.lang.Object[] array,
java.lang.Object key)
Gets the object stored with the given key, using only object equality. |
static java.lang.Object |
getByIdentity(java.lang.Object[] array,
java.lang.Object key)
Gets the object stored with the given key, using only object identity. |
static java.util.Enumeration |
getKeys(java.lang.Object[] array)
Returns an Enumeration of keys in the array. |
static java.util.Enumeration |
getValues(java.lang.Object[] array)
Returns an Enumeration of values in the array. |
int |
hashCode()
Computes the hashcode of an ArrayMap. |
boolean |
isEmpty()
Tests if this dictionary maps no keys to value. |
java.util.Enumeration |
keys()
Returns an enumeration of the keys in this dictionary. |
static java.lang.Object[] |
put(java.lang.Object[] array,
java.lang.Object key,
java.lang.Object value)
Adds the key/value pair to the array, returning a new array if necessary. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Maps the specified key to the specified
value in this dictionary. |
java.lang.Object |
remove(java.lang.Object key)
Removes the key (and its corresponding
value ) from this dictionary. |
static java.lang.Object[] |
remove(java.lang.Object[] array,
java.lang.Object key)
Removes the value for the key from the array, returning a new array if necessary. |
static java.lang.Object[] |
remove(java.lang.Object[] array,
java.lang.Object key,
boolean reallocate)
Removes the value for the key from the array, returning a new array if necessary. |
int |
size()
Returns the number of keys in this dictionary. |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ArrayMap()
public ArrayMap(int size)
size
- the number of elements to pre-allocate forpublic ArrayMap(int size, int increment)
size
- the number of elements to pre-allocate forincrement
- the number of additional elements to
allocate for when overruningpublic ArrayMap(java.util.Dictionary copy)
Method Detail |
public java.lang.Object clone()
clone
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int size()
size
in class java.util.Dictionary
public boolean isEmpty()
isEmpty
in class java.util.Dictionary
true
if this dictionary maps no keys to values;
false
otherwise.public java.util.Enumeration keys()
keys
in class java.util.Dictionary
Dictionary.elements()
,
Enumeration
public java.util.Enumeration elements()
elements
in class java.util.Dictionary
Dictionary.keys()
,
Enumeration
public java.lang.Object get(java.lang.Object key)
get
in class java.util.Dictionary
key
- a key in this dictionary.
null
if the key is not mapped to any value in
this dictionary.Dictionary.put(java.lang.Object, java.lang.Object)
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
key
to the specified
value
in this dictionary. Although normally neither
the key nor the value can be null
, we accidentally
released code where null
was allowed as a value,
and cannot now change the behavior.
The value
can be retrieved by calling the
get
method with a key
that is equal to
the original key
.
put
in class java.util.Dictionary
key
- the hashtable key.value
- the value.key
was mapped
in this dictionary, or null
if the key did not
have a previous mapping.NullPointerException
- if the key
or
value
is null
.Object.equals(java.lang.Object)
,
Dictionary.get(java.lang.Object)
public java.lang.Object remove(java.lang.Object key)
key
(and its corresponding
value
) from this dictionary. This method does nothing
if the key
is not in this dictionary.remove
in class java.util.Dictionary
key
- the key that needs to be removed.key
had been mapped in this
dictionary, or null
if the key did not have a
mapping.public boolean addAll(ArrayMap arrayMap)
public void clear()
public static java.lang.Object get(java.lang.Object[] array, java.lang.Object key)
public static java.lang.Object getByIdentity(java.lang.Object[] array, java.lang.Object key)
public static java.lang.Object getByEquality(java.lang.Object[] array, java.lang.Object key)
public static java.lang.Object[] put(java.lang.Object[] array, java.lang.Object key, java.lang.Object value)
public static java.lang.Object[] remove(java.lang.Object[] array, java.lang.Object key)
public static java.lang.Object[] remove(java.lang.Object[] array, java.lang.Object key, boolean reallocate)
public static java.util.Enumeration getKeys(java.lang.Object[] array)
public static java.util.Enumeration getValues(java.lang.Object[] array)
|
Bali Share 1.1.18 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |