structure
Class Table

java.lang.Object
  extended by structure.AbstractMap
      extended by structure.Table
All Implemented Interfaces:
Map, OrderedMap

public class Table
extends AbstractMap
implements OrderedMap

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

Field Summary
protected  OrderedStructure data
          An ordered structure that maintains the ComparableAssociations that store the key-value pairings.
 
Constructor Summary
Table()
          Construct a new, empty table.
Table(Table other)
           
 
Method Summary
 void clear()
          Remove all the elements of the table.
 boolean containsKey(java.lang.Object key)
          Determine if the key is in the table.
 boolean containsValue(java.lang.Object value)
          Returns true if the value is associated with some key in the table.
 Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
          Retrieve the value associated with the key provided.
 boolean isEmpty()
          Determine if the table is empty.
 java.util.Iterator iterator()
          Construct an iterator over the values of the table.
 java.util.Iterator keys()
          Construct an iterator over the keys of the table.
 Set keySet()
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Enter a key-value pair into the table.
 java.lang.Object remove(java.lang.Object key)
          Remove a key-value pair, based on key.
 int size()
          Determine the number of key-value pairs within the table.
 java.lang.String toString()
          Construct a string representing value of table.
 Structure values()
           
 
Methods inherited from class structure.AbstractMap
hashCode, putAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface structure.Map
equals, hashCode, putAll
 

Field Detail

data

protected OrderedStructure data
An ordered structure that maintains the ComparableAssociations that store the key-value pairings.

Constructor Detail

Table

public Table()
Construct a new, empty table.

Postcondition:
constructs a new table

Table

public Table(Table other)
Method Detail

get

public java.lang.Object get(java.lang.Object key)
Retrieve the value associated with the key provided. Be aware, the value may be null.

Specified by:
get in interface Map
Parameters:
key - The key of the key-value pair sought.
Returns:
The value associated with the key.
Precondition:
key is a non-null object
Postcondition:
returns value associated with key, or null

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.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.

Specified by:
put in interface Map
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.
Precondition:
key is non-null object
Postcondition:
key-value pair is added to table

isEmpty

public boolean isEmpty()
Determine if the table is empty.

Specified by:
isEmpty in interface Map
Returns:
True iff the table has no elements.
Postcondition:
returns true iff table is empty

clear

public void clear()
Remove all the elements of the table.

Specified by:
clear in interface Map
Postcondition:
removes all elements from the table

keys

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

Returns:
An iterator over the keys of the table.
Postcondition:
returns an iterator for traversing keys of table

iterator

public java.util.Iterator iterator()
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.

Returns:
An iterator over the values of the table.
Postcondition:
returns an iterator for traversing values in table

containsKey

public boolean containsKey(java.lang.Object key)
Determine if the key is in the table. The key should not be null.

Specified by:
containsKey in interface Map
Parameters:
key - A non-null key sought in the table.
Returns:
True iff the key is used in association with some value.
Precondition:
key is non-null object
Postcondition:
returns true iff key indexes a value in table

containsValue

public boolean containsValue(java.lang.Object value)
Returns true if the value is associated with some key in the table. This is often difficult to implement efficiently.

Specified by:
containsValue in interface Map
Parameters:
value - The value sought (possibly null).
Returns:
True, if the value is associated with some key in table.
Precondition:
value is non-null object
Postcondition:
returns true iff value in table

remove

public java.lang.Object remove(java.lang.Object key)
Remove a key-value pair, based on key. The value is returned.

Specified by:
remove in interface Map
Parameters:
key - The key of the key-value pair to be removed.
Returns:
The value associated with key, no longer in table.
Precondition:
key is non-null object
Postcondition:
removes value indexed in table

size

public int size()
Determine the number of key-value pairs within the table.

Specified by:
size in interface Map
Returns:
The number of key-value pairs in the table.
Postcondition:
returns number of key-value pairs in table

keySet

public Set keySet()
Specified by:
keySet in interface Map

values

public Structure values()
Specified by:
values in interface Map

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map

toString

public java.lang.String toString()
Construct a string representing value of table.

Overrides:
toString in class java.lang.Object
Returns:
String representing table.
Postcondition:
returns string representation