/** * A very simple entry for a dictionary. Note that while you can * change the value associated with an entry, you may not change * the key used. This restriction simplifies the implementation of * dictionaries. * * @author Samuel A. Rebelsky * @version 1.0 of April 2000 */ public class Entry { // +--------+---------------------------------------- // | Fields | // +--------+ /** The key of the entry. Should never be null. */ private Object key; /** * The associated value. May be null, although I'm not * sure what that would signify. */ private Object value; // +--------------+---------------------------------- // | Constructors | // +--------------+ /** * Build a new entry for the table. */ public Entry(Object finalKey, Object initialValue) { this.key = finalKey; this.value = initialValue; } // Entry(Object, Object) // +-----------+------------------------------------- // | Modifiers | // +-----------+ /** * Change the value associated with a particular key. */ public void setValue(Object newValue) { this.value = newValue; } // setValue(Object) // +------------+------------------------------------ // | Extractors | // +------------+ /** * Determine if this has the same key as another entry. */ public boolean equals(Entry otherEntry) { return this.key.equals(otherEntry.key); } // equals(Entry) /** * Determine if this entry equals another object. The * entry is only equal to another object if that object * is an entry with an equal key. */ public boolean equals(Object other) { if (other instanceof Entry) { return this.equals((Entry) other); } // the other thing is an entry else { return false; } // the other thing is not an entry } // equals(Object) /** * Get the key of this entry. */ public Object getKey() { return this.key; } // getKey() /** * Get the value of this entry. */ public Object getValue() { return this.value; } // getValue() /** * Get the hash code of this entry. */ public int hashCode() { return this.key.hashCode(); } // hashCode() } // class Entry