diff --git a/src/main/java/com/samskivert/depot/Tuple2.java b/src/main/java/com/samskivert/depot/Tuple2.java index c4932d1..124eb5f 100644 --- a/src/main/java/com/samskivert/depot/Tuple2.java +++ b/src/main/java/com/samskivert/depot/Tuple2.java @@ -22,16 +22,28 @@ package com.samskivert.depot; import java.io.Serializable; -import com.samskivert.depot.impl.QueryResult; +import com.google.common.base.Objects; /** - * Contains a two column result. + * Contains a two column result. This class is immutable and the objects it references are also + * meant to be immutable. They will generally contain only Depot primitive types (Java primitives, + * SQL primitives and some array types), which should be treated as immutable. */ public class Tuple2 implements Serializable { + /** The first column of the result. */ public final A a; + + /** The second column of the result. */ public final B b; + /** Constructs an initialized two tuple. */ + public static Tuple2 newTuple (A a, B b) + { + return new Tuple2(a, b); + } + + /** Constructs an initialized two tuple. */ public Tuple2 (A a, B b) { this.a = a; @@ -43,4 +55,21 @@ public class Tuple2 implements Serializable { return "[" + a + "," + b + "]"; } + + @Override + public int hashCode () + { + return Objects.hashCode(a, b); + } + + @Override + public boolean equals (Object other) + { + if (other instanceof Tuple2) { + Tuple2 otup = (Tuple2)other; + return Objects.equal(a, otup.a) && Objects.equal(b, otup.b); + } else { + return false; + } + } }