All Packages Class Hierarchy This Package Previous Next Index
Class structure.Table
java.lang.Object
|
+----structure.Table
- public class Table
- extends Object
- implements OrderedDictionary
An implementation of an ordered dictionary. Key-value pairs are
kept in the structure in order. To accomplish this, the keys of the
table must be comparable.
- See Also:
- Comparable
Table()
- Construct a new, empty table.
clear()
- Remove all the elements of the table.
contains(Object)
- Returns true if the value is associated with some key in the
table.
containsKey(Object)
- Determine if the key is in the table.
elements()
- Construct an iterator over the values of the table.
get(Object)
- Retrieve the value associated with the key provided.
isEmpty()
- Determine if the table is empty.
keys()
- Construct an iterator over the keys of the table.
put(Object, Object)
- Enter a key-value pair into the table.
remove(Object)
- Remove a key-value pair, based on key.
size()
- Determine the number of key-value pairs within the table.
toString()
- Construct a string representing value of table.
Table
public Table()
- Construct a new, empty table.
- Postcondition:
- constructs a new table
get
public Object get(Object key)
- Retrieve the value associated with the key provided.
Be aware, the value may be null.
- Precondition:
- key is a non-null object
- Postcondition:
- returns value associated with key, or null
- Parameters:
- key - The key of the key-value pair sought.
- Returns:
- The value associated with the key.
put
public Object put(Object key,
Object value)
- Enter a key-value pair into the table. if the key is already
in the table, 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.
- Precondition:
- key is non-null object
- Postcondition:
- key-value pair is added to table
- Parameters:
- key - The unique key in the table.
- value - The (possibly null) value associated with key.
- Returns:
- The prior value, or null if no prior value found.
isEmpty
public boolean isEmpty()
- Determine if the table is empty.
- Postcondition:
- returns true iff table is empty
- Returns:
- True iff the table has no elements.
clear
public void clear()
- Remove all the elements of the table.
- Postcondition:
- removes all elements from the table
keys
public Iterator keys()
- Construct an iterator over the keys of the table.
The order of the keys returned is in ascending order. It will
be consistent with that of the iterator from elements, provided
the table is not modified.
- Postcondition:
- returns an iterator for traversing keys of table
- Returns:
- An iterator over the keys of the table.
elements
public Iterator elements()
- Construct an iterator over the values of the table.
The order of the values returned is determined by order of keys. It will
be consistent with that of the iterator returned from keys, provided
the table is not modified.
- Postcondition:
- returns an iterator for traversing values in table
- Returns:
- An iterator over the values of the table.
containsKey
public boolean containsKey(Object key)
- Determine if the key is in the table. The key should
not be null.
- Precondition:
- key is non-null object
- Postcondition:
- returns true iff key indexes a value in table
- Parameters:
- key - A non-null key sought in the table.
- Returns:
- True iff the key is used in association with some value.
contains
public boolean contains(Object value)
- Returns true if the value is associated with some key in the
table. This is often difficult to implement efficiently.
- Precondition:
- value is non-null object
- Postcondition:
- returns true iff value in table
- Parameters:
- value - The value sought (possibly null).
- Returns:
- True, if the value is associated with some key in table.
remove
public Object remove(Object key)
- Remove a key-value pair, based on key. The value is returned.
- Precondition:
- key is non-null object
- Postcondition:
- removes value indexed in table
- Parameters:
- key - The key of the key-value pair to be removed.
- Returns:
- The value associated with key, no longer in table.
size
public int size()
- Determine the number of key-value pairs within the table.
- Postcondition:
- returns number of key-value pairs in table
- Returns:
- The number of key-value pairs in the table.
toString
public String toString()
- Construct a string representing value of table.
- Postcondition:
- returns string representation
- Returns:
- String representing table.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index