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