source: src/main/java/agents/anac/y2016/farma/etc/Pair.java

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

Initial import : Genius 9.0.0

File size: 847 bytes
Line 
1package agents.anac.y2016.farma.etc;
2
3import java.util.HashMap;
4import java.util.Map;
5
6class Pair<F, S> {
7 public final F first;
8 public final S second;
9
10 Pair(F first, S second) {
11 this.first = first;
12 this.second = second;
13 }
14
15 @Override
16 public boolean equals(Object obj) {
17 if (!(obj instanceof Pair))
18 return false;
19 Pair pair = (Pair) obj;
20 return (first.equals(pair.first) && second.equals(pair.second));
21 }
22
23 @Override
24 public int hashCode() {
25 return first.hashCode() ^ second.hashCode();
26 }
27
28 public static void main(String[] args) {
29 Map<Pair<Integer, Integer>, String> map = new HashMap<Pair<Integer, Integer>, String>();
30
31 Pair pair = new Pair(1, 2);
32 Pair pair2 = new Pair(1, 2);
33 map.put(pair, "a");
34
35 if (map.containsKey(pair2)) {
36 System.out.println("equal");
37 } else {
38 System.out.println("not equal");
39 }
40 }
41}
Note: See TracBrowser for help on using the repository browser.