|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--structure.Association
A class implementing a key-value pair. This class associates an immutable key with a mutable value. Used in many other structures.
Example Usage:
To store the number of classes a student has taken from five different professors and to output this information, we could use the following.
public static void main(String[] argv){
//store the number of classes taken by the student in an array of associations
Association [] classesTaken = new Association[5];
classesTaken[0] = new Association("Andrea", new Integer(5));
classesTaken[1] = new Association("Barbara", new Integer(1));
classesTaken[2] = new Association("Bill", new Integer(3));
classesTaken[3] = new Association("Duane", new Integer(2));
classesTaken[4] = new Association("Tom", new Integer(1));
//print out each item in the array
for (int i = 0; i< classesTaken.length; i++){
System.out.println("This Student has taken " + classesTaken[i].getValue() +
" classes from " + classesTaken[i].getKey()+ ".");
}
}
| 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 |
protected java.lang.Object theKey
protected java.lang.Object theValue
| Constructor Detail |
public Association(java.lang.Object key,
java.lang.Object value)
key - A non-null object.value - A (possibly null) object.public Association(java.lang.Object key)
key - A non-null key value.| Method Detail |
public boolean equals(java.lang.Object other)
equals in interface java.util.Map.Entryequals in class java.lang.Objectother - Another association.
public int hashCode()
hashCode in interface java.util.Map.EntryhashCode in class java.lang.ObjectHashtablepublic java.lang.Object getValue()
getValue in interface java.util.Map.Entrypublic java.lang.Object getKey()
getKey in interface java.util.Map.Entrypublic java.lang.Object setValue(java.lang.Object value)
setValue in interface java.util.Map.Entryvalue - The new value.public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||