/** * Checks if the pair contains <tt>o</tt>. The pair contains <tt>o</tt> if either the first or the * second member of the pair matches o. * * @param o The object to be checked against the members of the pair * @return True if o matches one of the members of the pair, else false. */ public boolean contains(Object o) { if (o == null) { return false; } else if (o.getClass() == x.getClass() || o.getClass() == y.getClass()) { return x.equals(o) || y.equals(o); } else { return false; } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; if (x != null ? !x.equals(pair.x) : pair.x != null) return false; return !(y != null ? !y.equals(pair.y) : pair.y != null); }
@Override public boolean equals(Object obj) { if (obj instanceof Tuple) { Tuple tuple = (Tuple) obj; // (x != null && tuple.x != null) ==> (x==tuple.x || x.equals(tuple.x)) // x == null <==> tuple.x == null boolean equalsX = (x == null && tuple.x == null) || ((x != null && tuple.x != null) && (x == tuple.x || x.equals(tuple.x))); boolean equalsY = (y == null && tuple.y == null) || ((y != null && tuple.y != null) && (y == tuple.y || y.equals(tuple.y))); return equalsX && equalsY; } return false; }
@Override public boolean equals(Object o) { @SuppressWarnings("unchecked") Pair<X, Y> p = (Pair<X, Y>) o; return a.equals(p.a) && b.equals(p.b); }