Make this into a proper value class.
This commit is contained in:
@@ -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<A,B> 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 <A, B> Tuple2<A, B> newTuple (A a, B b)
|
||||
{
|
||||
return new Tuple2<A, B>(a, b);
|
||||
}
|
||||
|
||||
/** Constructs an initialized two tuple. */
|
||||
public Tuple2 (A a, B b)
|
||||
{
|
||||
this.a = a;
|
||||
@@ -43,4 +55,21 @@ public class Tuple2<A,B> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user