source: src/main/java/agents/anac/y2011/TheNegotiator/Pair.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 1.1 KB
Line 
1package agents.anac.y2011.TheNegotiator;
2
3/**
4 * A simple tuple class.
5 *
6 * @author Alex Dirkzwager, Mark Hendrikx, Julian de Ruiter
7 */
8public class Pair<A, B> {
9
10 private A fst;
11 private B snd;
12
13 public Pair(A fst, B snd) {
14 this.fst = fst;
15 this.snd = snd;
16 }
17
18 public A getFirst() { return fst; }
19 public B getSecond() { return snd; }
20
21 public void setFirst(A v) { fst = v; }
22 public void setSecond(B v) { snd = v; }
23
24 public String toString() {
25 return "Pair[" + fst + "," + snd + "]";
26 }
27
28 private static boolean equals(Object x, Object y) {
29 return (x == null && y == null) || (x != null && x.equals(y));
30 }
31
32 public boolean equals(Object other) {
33 return
34 other instanceof Pair &&
35 equals(fst, ((Pair<?, ?>)other).fst) &&
36 equals(snd, ((Pair<?, ?>)other).snd);
37 }
38
39 public int hashCode() {
40 if (fst == null) return (snd == null) ? 0 : snd.hashCode() + 1;
41 else if (snd == null) return fst.hashCode() + 2;
42 else return fst.hashCode() * 17 + snd.hashCode();
43 }
44
45 public static <A,B> Pair<A,B> of(A a, B b) {
46 return new Pair<A,B>(a,b);
47 }
48}
Note: See TracBrowser for help on using the repository browser.