finiteAutomata
Class Association

java.lang.Object
  extended by finiteAutomata.Association
All Implemented Interfaces:
java.util.Map.Entry

public class Association
extends java.lang.Object
implements java.util.Map.Entry

A key-value pair such that the key cannot be modified. Associations are used by the Hashtable class. Adapted from code in "Java Structures: Data Structures in Java for the Principled Programmer", 2nd edition, Duane A. Bailey, 2003 (McGraw-Hill Publishers), p.14.

Version:
Fall 2007
Author:
Barbara Wahl

Field Summary
protected  java.lang.Object theKey
          the key
protected  java.lang.Object theValue
          the value
 
Constructor Summary
Association(java.lang.Object key)
          1-parameter constructor.
Association(java.lang.Object key, java.lang.Object value)
          2-parameter constructor.
 
Method Summary
 boolean equals(java.lang.Object other)
          Tests whether this Association and the given Association have equal keys.
 java.lang.Object getKey()
          Returns the key.
 java.lang.Object getValue()
          Returns the value.
static void main(java.lang.String[] args)
           
 java.lang.Object setValue(java.lang.Object value)
          Sets the value of this Association to the given Object.
 java.lang.String toString()
          Converts this Association to a String for pretty-printing.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map.Entry
hashCode
 

Field Detail

theKey

protected java.lang.Object theKey
the key


theValue

protected java.lang.Object theValue
the value

Constructor Detail

Association

public Association(java.lang.Object key,
                   java.lang.Object value)
2-parameter constructor.

Parameters:
key - Object to store as the key
value - Object to store as the value
Precondition:
key is not null
Postcondition:
creates an Association with the given key and value

Association

public Association(java.lang.Object key)
1-parameter constructor.

Parameters:
key - Object to store as the key
Precondition:
key is not null
Postcondition:
creates an Association with the given key and a null value
Method Detail

getKey

public java.lang.Object getKey()
Returns the key.

Specified by:
getKey in interface java.util.Map.Entry
Returns:
Object theKey

getValue

public java.lang.Object getValue()
Returns the value.

Specified by:
getValue in interface java.util.Map.Entry
Returns:
Object theValue (may be null)

toString

public java.lang.String toString()
Converts this Association to a String for pretty-printing.

Overrides:
toString in class java.lang.Object
Returns:
String representation of this Association as an ordered pair (inserts "null" in place of theValue.toString() if the value is null)

setValue

public java.lang.Object setValue(java.lang.Object value)
Sets the value of this Association to the given Object.

Specified by:
setValue in interface java.util.Map.Entry
Parameters:
value - Object to store as the new value
Returns:
(Object) the old value of this Association

equals

public boolean equals(java.lang.Object other)
Tests whether this Association and the given Association have equal keys.

Specified by:
equals in interface java.util.Map.Entry
Overrides:
equals in class java.lang.Object
Parameters:
other - Association to compare with this
Returns:
true iff the two keys are equal, according to the appropriate equals method
Precondition:
other is a non-null Association

main

public static void main(java.lang.String[] args)