Skip to content

Instantly share code, notes, and snippets.

@wobondar
Created May 26, 2018 07:26
Show Gist options
  • Select an option

  • Save wobondar/092b6a1cd8a59ddb1d36ab9112965d60 to your computer and use it in GitHub Desktop.

Select an option

Save wobondar/092b6a1cd8a59ddb1d36ab9112965d60 to your computer and use it in GitHub Desktop.
Tuple generic for two objects
public class Tuple<L,R> {
private final L left;
private final R right;
public Tuple(L left, R right) {
this.left = left;
this.right = right;
}
public L getLeft() { return left; }
public R getRight() { return right; }
@Override
public int hashCode() { return left.hashCode() ^ right.hashCode(); }
@Override
public boolean equals(Object o) {
if (!(o instanceof Tuple)) return false;
Tuple tuple = (Tuple) o;
return this.left.equals(tuple.getLeft()) &&
this.right.equals(tuple.getRight());
}
@Override
public String toString() {
return "Tuple{" + left.getClass().getSimpleName() + "=" + left + ", " + right.getClass().getSimpleName() + "=" + right + '}';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment