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
59
60
61
62 public static <T1,T2> Pair<T1,T2> newPair(T1 a, T2 b) {
63 return new Pair<T1,T2>(a, b);
64 }
65
66
67
68
69
70 public void setFirst(T1 a)
71 {
72 this.first = a;
73 }
74
75
76
77
78
79 public void setSecond(T2 b)
80 {
81 this.second = b;
82 }
83
84
85
86
87
88 public T1 getFirst()
89 {
90 return first;
91 }
92
93
94
95
96
97 public T2 getSecond()
98 {
99 return second;
100 }
101
102 private static boolean equals(Object x, Object y)
103 {
104 return (x == null && y == null) || (x != null && x.equals(y));
105 }
106
107 @Override
108 @SuppressWarnings("unchecked")
109 public boolean equals(Object other)
110 {
111 return other instanceof Pair && equals(first, ((Pair)other).first) &&
112 equals(second, ((Pair)other).second);
113 }
114
115 @Override
116 public int hashCode()
117 {
118 if (first == null)
119 return (second == null) ? 0 : second.hashCode() + 1;
120 else if (second == null)
121 return first.hashCode() + 2;
122 else
123 return first.hashCode() * 17 + second.hashCode();
124 }
125
126 @Override
127 public String toString()
128 {
129 return "{" + getFirst() + "," + getSecond() + "}";
130 }
131 }