Bali Share 1.1.18

oracle.bali.share.collection
Class ArrayMap

java.lang.Object
  |
  +--java.util.Dictionary
        |
        +--oracle.bali.share.collection.ArrayMap
All Implemented Interfaces:
java.lang.Cloneable

public class ArrayMap
extends java.util.Dictionary
implements java.lang.Cloneable

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

ArrayMap

public ArrayMap()
Creates an empty ArrayMap, preallocating nothing.

ArrayMap

public ArrayMap(int size)
Creates an ArrayMap, preallocating for a certain size.
Parameters:
size - the number of elements to pre-allocate for

ArrayMap

public ArrayMap(int size,
                int increment)
Creates an ArrayMap, preallocating for a certain size.
Parameters:
size - the number of elements to pre-allocate for
increment - the number of additional elements to allocate for when overruning

ArrayMap

public ArrayMap(java.util.Dictionary copy)
Creates an ArrayMap from another Dictionary.
Method Detail

clone

public java.lang.Object clone()
Clones the map.
Overrides:
clone in class java.lang.Object

hashCode

public int hashCode()
Computes the hashcode of an ArrayMap.
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Determines if this ArrayMap is equal to another object.
Overrides:
equals in class java.lang.Object

size

public int size()
Returns the number of keys in this dictionary.
Overrides:
size in class java.util.Dictionary
Returns:
the number of keys in this dictionary.
Since:
JDK1.0

isEmpty

public boolean isEmpty()
Tests if this dictionary maps no keys to value.
Overrides:
isEmpty in class java.util.Dictionary
Returns:
true if this dictionary maps no keys to values; false otherwise.
Since:
JDK1.0

keys

public java.util.Enumeration keys()
Returns an enumeration of the keys in this dictionary.
Overrides:
keys in class java.util.Dictionary
Returns:
an enumeration of the keys in this dictionary.
Since:
JDK1.0
See Also:
Dictionary.elements(), Enumeration

elements

public java.util.Enumeration elements()
Returns an enumeration of the values in this dictionary. the Enumeration methods on the returned object to fetch the elements sequentially.
Overrides:
elements in class java.util.Dictionary
Returns:
an enumeration of the values in this dictionary.
Since:
JDK1.0
See Also:
Dictionary.keys(), Enumeration

get

public java.lang.Object get(java.lang.Object key)
Returns the value to which the key is mapped in this dictionary.
Overrides:
get in class java.util.Dictionary
Parameters:
key - a key in this dictionary. null if the key is not mapped to any value in this dictionary.
Returns:
the value to which the key is mapped in this dictionary;
Since:
JDK1.0
See Also:
Dictionary.put(java.lang.Object, java.lang.Object)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Maps the specified 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.

Overrides:
put in class java.util.Dictionary
Parameters:
key - the hashtable key.
value - the value.
Returns:
the previous value to which the key was mapped in this dictionary, or null if the key did not have a previous mapping.
Throws:
NullPointerException - if the key or value is null.
Since:
JDK1.0
See Also:
Object.equals(java.lang.Object), Dictionary.get(java.lang.Object)

remove

public java.lang.Object remove(java.lang.Object key)
Removes the key (and its corresponding value) from this dictionary. This method does nothing if the key is not in this dictionary.
Overrides:
remove in class java.util.Dictionary
Parameters:
key - the key that needs to be removed.
Returns:
the value to which the key had been mapped in this dictionary, or null if the key did not have a mapping.
Since:
JDK1.0

addAll

public boolean addAll(ArrayMap arrayMap)
Adds all elements from another ArrayMap into this map.
Returns:
true if any elements were inserted

clear

public void clear()
Removes all elements from the ArrayMap.

get

public static java.lang.Object get(java.lang.Object[] array,
                                   java.lang.Object key)
Gets the object stored with the given key. Scans first by object identity, then by object equality.

getByIdentity

public 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.

getByEquality

public 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.

put

public 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.

remove

public 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.

remove

public 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.

getKeys

public static java.util.Enumeration getKeys(java.lang.Object[] array)
Returns an Enumeration of keys in the array.

getValues

public static java.util.Enumeration getValues(java.lang.Object[] array)
Returns an Enumeration of values in the array.

Bali Share 1.1.18