Created
May 26, 2018 07:26
-
-
Save wobondar/092b6a1cd8a59ddb1d36ab9112965d60 to your computer and use it in GitHub Desktop.
Tuple generic for two objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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