Last active
July 9, 2016 01:46
-
-
Save sc0rch/7a57e0b2c5a45962de33d228d2e7bb1e to your computer and use it in GitHub Desktop.
Simple Tuple-type template for Java.
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
/** | |
* Created by sc0rch on 05.07.16. | |
*/ | |
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 t = (Tuple) o; | |
return this.left.equals(t.getLeft()) && | |
this.right.equals(t.getRight()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment