1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.util;
22
23 import java.io.Serializable;
24
25
26
27
28
29
30 public class Pair<T1, T2> implements Serializable
31 {
32 private static final long serialVersionUID = -3986244606585552569L;
33 protected T1 first = null;
34 protected T2 second = null;
35
36
37
38
39 public Pair()
40 {
41 }
42
43
44
45
46
47
48 public Pair(T1 a, T2 b)
49 {
50 this.first = a;
51 this.second = b;
52 }
53
54
55
56
57
58 public void setFirst(T1 a)
59 {
60 this.first = a;
61 }
62
63
64
65
66
67 public void setSecond(T2 b)
68 {
69 this.second = b;
70 }
71
72
73
74
75
76 public T1 getFirst()
77 {
78 return first;
79 }
80
81
82
83
84
85 public T2 getSecond()
86 {
87 return second;
88 }
89
90 private static boolean equals(Object x, Object y)
91 {
92 return (x == null && y == null) || (x != null && x.equals(y));
93 }
94
95 @Override
96 @SuppressWarnings("unchecked")
97 public boolean equals(Object other)
98 {
99 return other instanceof Pair && equals(first, ((Pair)other).first) &&
100 equals(second, ((Pair)other).second);
101 }
102
103 @Override
104 public int hashCode()
105 {
106 if (first == null)
107 return (second == null) ? 0 : second.hashCode() + 1;
108 else if (second == null)
109 return first.hashCode() + 2;
110 else
111 return first.hashCode() * 17 + second.hashCode();
112 }
113
114 @Override
115 public String toString()
116 {
117 return "{" + getFirst() + "," + getSecond() + "}";
118 }
119 }