source: src/main/java/agents/anac/y2010/Southampton/utils/Pair.java@ 1

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

Initial import : Genius 9.0.0

File size: 828 bytes
Line 
1package agents.anac.y2010.Southampton.utils;
2
3public class Pair<A, B> {
4
5 public final A fst;
6 public final B snd;
7
8 public Pair(A fst, B snd) {
9 this.fst = fst;
10 this.snd = snd;
11 }
12
13 public String toString() {
14 return "Pair[" + fst + "," + snd + "]";
15 }
16
17 private static boolean equals(Object x, Object y) {
18 return (x == null && y == null) || (x != null && x.equals(y));
19 }
20
21 public boolean equals(Object other) {
22 return other instanceof Pair && equals(fst, ((Pair<?, ?>) other).fst) && equals(snd, ((Pair<?, ?>) other).snd);
23 }
24
25 public int hashCode() {
26 if (fst == null)
27 return (snd == null) ? 0 : snd.hashCode() + 1;
28 else if (snd == null)
29 return fst.hashCode() + 2;
30 else
31 return fst.hashCode() * 17 + snd.hashCode();
32 }
33
34 public static <A, B> Pair<A, B> of(A a, B b) {
35 return new Pair<A, B>(a, b);
36 }
37}
Note: See TracBrowser for help on using the repository browser.