package rebelsky.dict; /** * Key value pairs useful for implementing dictionaries. * * @author CSC152 2004F * @version 1.1 of November 2004 */ class KeyedValue { // +--------+-------------------------------------------------- // | Fields | // +--------+ Object key; Object value; // +--------------+-------------------------------------------- // | Constructors | // +--------------+ public KeyedValue(Object _key, Object _value) { this.key = _key; this.value = _value; } // KeyedValue(Object, Object) // +---------+------------------------------------------------- // | Methods | // +---------+ /** * Convert to a string, typically for output. */ public String toString() { return this.key.toString() + ":" + this.value.toString(); } // toString() /** * Compare to another object for equality. For the other object * to be equal, it must be an equal KeyedValue. */ public boolean equals(Object other) { return equals((KeyedValue) other); } // equals /** * Determine if another keyed value equals this object. Two keyed * values are equal if they have the same key. */ public boolean equals(KeyedValue other) { return this.key.equals(other.key); } // equals(KeyedValue) /** * Return a value useful for hashing. */ public int hashCode() { return this.key.hashCode(); } // hashCode() } // class KeyedValue