package dict; import java.lang.*; /** * Represents a (key, value) pair stored in a dictionary, * where key is a Comparable. */ public class DictionaryPair implements Comparable { private Comparable _key; private Object _value; /** * Initializes this DictionaryPair to a given (key, value) pair. */ public DictionaryPair(Comparable key, Object value) { _key = key; _value = value; } /** * Compares the key of this DictionaryPair against the key of the * other DictionayPair. * @param other a DictionaryPair */ public int compareTo(Object other) { return _key.compareTo(((DictionaryPair)other)._key); } /** * Returns the key of this DictionaryPair. */ public Comparable getKey() { return _key; } /** * Returns the value of this DictionaryPair. */ public Object getValue() { return _value; } /** * Shows "(", followed by the String representation of the key, followed by * a ",", followed by the String representation of the associcated value, * followed by a ")". */ public String toString() { return "(" + _key + "," + _value + ")"; } }