Class next.util.ImmutableHashtable

CLASS DESCRIPTION

Extends:
next.util.NextObject

Implements:
next/util/Coding

The ImmutableHashtable class declares the programmatic interface to objects that manage immutable associations of keys and values. ImmutableHashtable three primitive methods-size, get, and keys-provide the basis for all of the other methods in its interface. The size method returns the number of entries in the ImmutableHashtable. get returns the value associated with a given key. keys returns an object that lets you iterate through each of the keys in the ImmutableHashtable.

The other methods declared here operate by invoking one or more of these primitives. The non-primitive methods provide convenient ways of accessing multiple entries at once. A key-value pair within an ImmutableHashtable is called an entry. Each entry consists of one object that represents the key, and a second object which is that key's value. Within an ImmutableHashtable, the keys are unique. That is, no two keys in a single ImmutableHashtable are equal.

You establish an ImmutableHashtable's entries when it's created, and thereafter the entries can't be modified. A mutable hashtable allows the addition and deletion of entries at any time, automatically allocating memory as needed.


CONSTRUCTORS

ImmutableHashtable

public ImmutableHashtable()
public ImmutableHashtable(java.lang.Object[] keys, java.lang.Object[] objects)
public ImmutableHashtable(java.lang.String path)
public ImmutableHashtable(java.util.Hashtable aHashtable)

Creates and returns an ImmutableHashtable.

If no parameters are supplied, the returned hashtable will be empty. This is used primarily by mutable subclasses of ImmutableHashtable.

If you supply both keys and objects, the returned ImmutableHashtable is initialized with entries constructed from the contents of the keys and objects arrays. This method steps through the keys and objects arrays, creating entries in the new ImmutableHashtable as it goes. An exception is raised if the objects and keys arrays do not have the same number of elements.

If you supply path. the returned dictionary contains the keys and values found in the file specified by path. path can be a full or relative pathname; the file that it names must contain a string representation of an ImmutableHashtable. nil is returned if there's a file error or if the contents of the file is an invalid representation of a ImmutableHashtable.

If you supply aHashtable, the returned ImmutableHashtable will be initialized with the contents of the specified Java Hashtable.


METHODS

allKeysForObject

public next.util.ImmutableVector allKeysForObject(java.lang.Object anObject)

Finds all occurrences of the value anObject in the ImmutableHashtable and returns a new vector with the corresponding keys. If no object matching anObject is found, this method returns nil.


contains

public boolean contains(java.lang.Object anObject)

Returns whether the ImmutableHashtable contains at least key-value pair where the value is equal to anObject.


containsKey

public boolean containsKey(java.lang.Object aKey)

Returns whether the ImmutableHashtable contains a least key-value pair where the key is equal to aKey.


elements

public java.util.Enumeration elements()

Returns an enumerator object that lets you access each value in the ImmutableHashtable. When this method is used with mutable hashtables, your code shouldn't modify the entries during enumeration. If you intend to modify the entries, use the elements method to create a "snapshot" of the hashtable's values. Work from this snapshot to modify the values.


encodeWithCoder

public void encodeWithCoder(next.util.Coder aCoder)

Encodes the receiver using aCoder. See the Coding interface description for more information.


get

public java.lang.Object get(java.lang.Object aKey)

Returns an entry's value given its key, or nil if no value is associated with aKey.


getKeys

protected void getKeys(java.lang.Object[] keys)

Returns the ImmutableHashtable's keys in keys. The order of the elements in the array isn't defined.


getObjects

protected void getObjects(java.lang.Object[] objects)

Returns the ImmutableHashtable's values in objects. The order of the elements in the array isn't defined.


hashtable

public java.util.Hashtable hashtable()

Returns a Java hashtable containing the receiver's key-value pairs.


initWithKeysAndObjects

protected void initWithKeysAndObjects(java.lang.Object[] keys, java.lang.Object[] objects)

Initializes the receiver with entries constructed from the contents of the keys and objects arrays. This method steps through the keys and objects arrays, creating entries in the new ImmutableHashtable as it goes. An exception is raised if the objects and keys arrays do not have the same number of elements.


isEmpty

public boolean isEmpty()

Returns true if the receiver has no entries.


keys

public java.util.Enumeration keys()

Returns an enumerator object that lets you access each key in the ImmutableHashtable. When this method is used with mutable subclasses of ImmutableHashtable, your code shouldn't modify the entries during enumeration. If you intend to modify the entries, use the elements method to create a "snapshot" of the Hashtable's keys. Then use this snapshot to traverse the entries, modifying them along the way.

Note that the elements method provides a convenient way to access each value in the ImmutableHashtable.


size

public int size()

Returns the number of entries in the ImmutableHashtable.