/** A class to represent two values. * @author Lew, * snagged from http://groups.google.com/group/comp.lang.java.help/browse_thread/thread/f8b63fc645c1b487/1d94be050cfc249b * minimally touched up by Ian Barland. * @version 2008.Dec.06 */ public class Pair { private final T first; private final U second; private transient final int hash; /* @param f The first value of this pair. * @param s The second value of this pair. */ public Pair( T f, U s ) { this.first = f; this.second = s; hash = (first == null? 0 : first.hashCode() * 31) + (second == null? 0 : second.hashCode()); } /** Return The first value of this pair. * @return The first value of this pair. */ public T getFirst() { return first; } /** Return The second value of this pair. * @return The second value of this pair. */ public U getSecond() { return second; } @Override public int hashCode() { return hash; } @Override public boolean equals( Object oth ) { if ( this == oth ) { return true; } else if ( oth == null || !(this.getClass().isInstance( oth )) ) { return false; } else { Pair other = getClass().cast( oth ); // This line will generate a 'unchecked type operation' warning. return (first == null? other.first == null : first.equals( other.first )) && (second == null? other.second == null : second.equals( other.second )); } } }