Rev | Line | |
---|
[1] | 1 | package geniusweb.blingbling.Ranknet;
|
---|
| 2 |
|
---|
| 3 | import java.util.Objects;
|
---|
| 4 |
|
---|
| 5 | public class Pair<A, B> {
|
---|
| 6 |
|
---|
| 7 | public final A fst;
|
---|
| 8 | public final B snd;
|
---|
| 9 |
|
---|
| 10 | public Pair(A fst, B snd) {
|
---|
| 11 | this.fst = fst;
|
---|
| 12 | this.snd = snd;
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | public String toString() {
|
---|
| 16 | return "Pair[" + fst + "," + snd + "]";
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | public boolean equals(Object other) {
|
---|
| 20 | return
|
---|
| 21 | other instanceof Pair<?,?> &&
|
---|
| 22 | Objects.equals(fst, ((Pair<?,?>)other).fst) &&
|
---|
| 23 | Objects.equals(snd, ((Pair<?,?>)other).snd);
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | public int hashCode() {
|
---|
| 27 | if (fst == null) return (snd == null) ? 0 : snd.hashCode() + 1;
|
---|
| 28 | else if (snd == null) return fst.hashCode() + 2;
|
---|
| 29 | else return fst.hashCode() * 17 + snd.hashCode();
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | public static <A,B> Pair<A,B> of(A a, B b) {
|
---|
| 33 | return new Pair<>(a,b);
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.