diff --git a/projects/samskivert/src/java/com/samskivert/util/Tuple.java b/projects/samskivert/src/java/com/samskivert/util/Tuple.java index 26ead0ed..334070d6 100644 --- a/projects/samskivert/src/java/com/samskivert/util/Tuple.java +++ b/projects/samskivert/src/java/com/samskivert/util/Tuple.java @@ -1,5 +1,5 @@ // -// $Id: Tuple.java,v 1.2 2001/08/11 22:43:29 mdb Exp $ +// $Id: Tuple.java,v 1.3 2001/11/26 19:22:12 mdb Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -22,6 +22,8 @@ package com.samskivert.util; /** * A tuple is a simple object that holds a reference to two other objects. + * It provides hashcode and equality semantics that allow it to be used to + * combine two objects into a single key (for hashtables, etc.). */ public class Tuple { @@ -43,6 +45,32 @@ public class Tuple { } + /** + * Returns the combined hashcode of the two elements. + */ + public int hashCode () + { + return left.hashCode() ^ right.hashCode(); + } + + /** + * A tuple is equal to another tuple if the left and right elements + * are equal to the left and right elements (respectively) of the + * other tuple. + */ + public boolean equals (Object other) + { + if (other instanceof Tuple) { + Tuple to = (Tuple)other; + return (left.equals(to.left) && right.equals(to.right)); + } else { + return false; + } + } + + /** + * Generates a string representation of this tuple. + */ public String toString () { return "[left=" + left + ", right=" + right + "]";