All Packages  Class Hierarchy  This Package  Previous  Next  Index  

Interface structure.Dictionary

public interface Dictionary
extends Store
This interface describes a Dictionary --- a collection of key-value pairs. The interface is motivated largely by the interface found in java.util. In this model, every entry of the dictionary is identified by a unique key. This key is associated with a value, which may or may not be unique. The values associated with keys may be modified, but the keys may not. (Key-value pairs may be removed and the value reinserted.)

Traversal through the structure is accomplished with two iterators, elements, and keys. These iterators are guaranteed to traverse the structure in the same order, so that the key-value relationship may be extracted by parallel iteration.


Method Index

 o contains(Object)
Returns true if the value is associated with some key in the dictionary.
 o containsKey(Object)
Determine if the key is in the dictionary.
 o elements()
Construct an iterator over the values of the dictionary.
 o get(Object)
Retrieve the value associated with the key provided.
 o keys()
Construct an iterator over the keys of the dictionary.
 o put(Object, Object)
Enter a key-value pair into the dictionary.
 o remove(Object)
Remove a key-value pair, based on key.
 o size()
Determine the number of key-value pairs within the dictionary.

Methods

 o put
public abstract Object put(Object key,
                           Object value)
Enter a key-value pair into the dictionary. if the key is already in the dictionary, the old value is returned, and the old key-value pair is replaced. Otherwise null is returned. The user is cautioned that a null value returned may indicate there was no prior key-value pair, or --- if null values are inserted --- that the key was previously associated with a null value.

pre: key is non-null post: puts key-value pair in Dictionary, returns old value

Parameters:
key - The unique key in the dictionary.
value - The (possibly null) value associated with key.
Returns:
The prior value, or null if no prior value found.
 o contains
public abstract boolean contains(Object value)
Returns true if the value is associated with some key in the dictionary. This is often difficult to implement efficiently.

Precondition:
value is non-null
Postcondition:
returns true iff the dictionary contains the value

Parameters:
value - The value sought (possibly null).
Returns:
True, if the value is associated with some key in dictionary.
 o containsKey
public abstract boolean containsKey(Object key)
Determine if the key is in the dictionary. The key should not be null.

Precondition:
key is non-null
Postcondition:
returns true iff the dictionary contains the key

Parameters:
key - A non-null key sought in the dictionary.
Returns:
True iff the key is used in association with some value.
 o remove
public abstract Object remove(Object key)
Remove a key-value pair, based on key. The value is returned.

Precondition:
value is non-null
Postcondition:
removes an object "equal" to value within dictionary.

Parameters:
key - The key of the key-value pair to be removed.
Returns:
The value associated with key, no longer in dictionary.
 o get
public abstract Object get(Object key)
Retrieve the value associated with the key provided. Be aware, the value may be null.

Precondition:
key is non-null
Postcondition:
returns value associated with key, in dictionary

Parameters:
key - The key of the key-value pair sought.
Returns:
The value associated with the key.
 o keys
public abstract Iterator keys()
Construct an iterator over the keys of the dictionary. The order of the keys returned is not predictable, but it will be consistent with that of the iterator from elements, provided the dictionary is not modified.

Postcondition:
returns iterator for traversing keys in dictionary

Returns:
An iterator over the keys of the dictionary.
 o elements
public abstract Iterator elements()
Construct an iterator over the values of the dictionary. The order of the values returned is not predictable, but it will be consistent with that of the iterator returned from keys, provided the dictionary is not modified.

Postcondition:
returns iterator for traversing values in dictionary

Returns:
An iterator over the values of the dictionary.
 o size
public abstract int size()
Determine the number of key-value pairs within the dictionary.

Postcondition:
returns number of elements in dictionary

Returns:
The number of key-value pairs within the dictionary.

All Packages  Class Hierarchy  This Package  Previous  Next  Index