/** * An ordered pair is a pair which is ordered lexicographically. * * @author Rossmanith * * @param The type of the first value. * @param The type of the second value. */ public class OPair,B extends Comparable> extends Pair implements Comparable> { /** * Create a new pair with first value a and second value b * @param a The first value * @param b The second value */ public OPair(A a, B b) { super(a, b); } /** * Equality is defined pairwise, i.e. [a1,b1] = [a2,b2] iff * a1 = a2 and b1 = b2. Note that o must be an ordered pair. * @param o The object to compare with this. */ @SuppressWarnings("unchecked") @Override public boolean equals(Object o) { OPair p = (OPair) o; return a.equals(p.a) && b.equals(p.b); } /** * Compares this pair with another pair p. Here * [a1,b1] is smaller/greater than [a2,b2] iff * a1 is smaller/greater than a2 or, if a1 = a2 then * b1 is smaller/greater than b2 * @param p t * @return a negative number, if this < p, * 0, if this = p, * and a positive number, if this > p (confere the contract of {@link java.lang.Comparable}) * @see java.lang.Comparable */ public int compareTo(OPair p) { if(a.equals(p.a)) return b.compareTo(p.b); else return a.compareTo(p.a); } @Override public int hashCode() { return (a.hashCode() << 8 | b.hashCode()); } }