structure
Class Association

java.lang.Object
  extended by structure.Association
All Implemented Interfaces:
java.util.Map.Entry
Direct Known Subclasses:
ComparableAssociation

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

A class implementing a key-value pair. This class associates an immutable key with a mutable value. Used in many other structures.


Field Summary
protected  java.lang.Object theKey
          The immutable key.
protected  java.lang.Object theValue
          The mutable value.
 
Constructor Summary
Association(java.lang.Object key)
          Constructs a pair from a key; value is null.
Association(java.lang.Object key, java.lang.Object value)
          Constructs a pair from a key and value.
 
Method Summary
 boolean equals(java.lang.Object other)
          Standard comparison function.
 java.lang.Object getKey()
          Fetch key from association.
 java.lang.Object getValue()
          Fetch value from association.
 int hashCode()
          Standard hashcode function.
 java.lang.Object setValue(java.lang.Object value)
          Sets the value of the key-value pair.
 java.lang.String toString()
          Standard string representation of an association.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

theKey

protected java.lang.Object theKey
The immutable key. An arbitrary object.


theValue

protected java.lang.Object theValue
The mutable value. An arbitrary object.

Constructor Detail

Association

public Association(java.lang.Object key,
                   java.lang.Object value)
Constructs a pair from a key and value.

Parameters:
key - A non-null object.
value - A (possibly null) object.
Precondition:
key is non-null
Postcondition:
constructs a key-value pair

Association

public Association(java.lang.Object key)
Constructs a pair from a key; value is null.

Parameters:
key - A non-null key value.
Precondition:
key is non-null
Postcondition:
constructs a key-value pair; value is null
Method Detail

equals

public boolean equals(java.lang.Object other)
Standard comparison function. Comparison based on keys only.

Specified by:
equals in interface java.util.Map.Entry
Overrides:
equals in class java.lang.Object
Parameters:
other - Another association.
Returns:
true iff the keys are equal.
Precondition:
other is non-null Association
Postcondition:
returns true iff the keys are equal

hashCode

public int hashCode()
Standard hashcode function.

Specified by:
hashCode in interface java.util.Map.Entry
Overrides:
hashCode in class java.lang.Object
Returns:
A hash code for association.
See Also:
Hashtable
Postcondition:
return hash code association with this association

getValue

public java.lang.Object getValue()
Fetch value from association. May return null.

Specified by:
getValue in interface java.util.Map.Entry
Returns:
The value field of the association.
Postcondition:
returns value from association

getKey

public java.lang.Object getKey()
Fetch key from association. Should not return null.

Specified by:
getKey in interface java.util.Map.Entry
Returns:
Key of the key-value pair.
Postcondition:
returns key from association

setValue

public java.lang.Object setValue(java.lang.Object value)
Sets the value of the key-value pair.

Specified by:
setValue in interface java.util.Map.Entry
Parameters:
value - The new value.
Postcondition:
sets association's value to value

toString

public java.lang.String toString()
Standard string representation of an association.

Overrides:
toString in class java.lang.Object
Returns:
String representing key-value pair.
Postcondition:
returns string representation