/** * A key/value pair. Useful for association lists and other * implementations of dictionaries. Once you have created a * pair, you cannot change either the key or the value. * * @author Samuel A. Rebelsky * @version 1.0 of November 1999 */ public class Pair { // +--------+-------------------------------------------------- // | Fields | // +--------+ /** The key of the pair. */ private Object key; /** The value in the pair. */ private Object value; // +--------------+-------------------------------------------- // | Constructors | // +--------------+ /** Build a new key/value pair. */ public Pair(Object key, Object value) { this.key = key; this.value = value; } // Pair(Object, Object) // +---------+------------------------------------------------- // | Methods | // +---------+ /** Get the key. */ public Object getKey() { return this.key; } // getKey() /** Get the value. */ public Object getValue() { return this.value; } // getValue() /** Determine if another pair has the same key. */ public boolean equals(Pair other) { return this.key.equals(other.key); } // equals(Pair) /** * Determine if another object is equal to this pair. The other * object must be a pair and an equal pair. */ public boolean equals(Object other) { return ( (other instanceof Pair) && (this.equals((Pair) other)) ); } // equals(Object) /** * Convert to a string. */ public String toString() { return "[" + this.key + "->" + this.value + "]"; } // toString() } // class Pair