View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.util;
20  
21  /**
22   * Utility class to manage a triple.
23   */
24  public class Triple<A, B, C> {
25    private A first;
26    private B second;
27    private C third;
28  
29    public Triple(A first, B second, C third) {
30      this.first = first;
31      this.second = second;
32      this.third = third;
33    }
34  
35    public int hashCode() {
36      int hashFirst = (first != null ? first.hashCode() : 0);
37      int hashSecond = (second != null ? second.hashCode() : 0);
38      int hashThird = (third != null ? third.hashCode() : 0);
39  
40      return (hashFirst >> 1) ^ hashSecond ^ (hashThird << 1);
41    }
42  
43    public boolean equals(Object obj) {
44      if (!(obj instanceof Triple)) {
45        return false;
46      }
47  
48      Triple<?, ?, ?> otherTriple = (Triple<?, ?, ?>) obj;
49  
50      if (first != otherTriple.first && (first != null && !(first.equals(otherTriple.first))))
51        return false;
52      if (second != otherTriple.second && (second != null && !(second.equals(otherTriple.second))))
53        return false;
54      if (third != otherTriple.third && (third != null && !(third.equals(otherTriple.third))))
55        return false;
56  
57      return true;
58    }
59  
60    public String toString() {
61      return "(" + first + ", " + second + "," + third + " )";
62    }
63  
64    public A getFirst() {
65      return first;
66    }
67  
68    public void setFirst(A first) {
69      this.first = first;
70    }
71  
72    public B getSecond() {
73      return second;
74    }
75  
76    public void setSecond(B second) {
77      this.second = second;
78    }
79  
80    public C getThird() {
81      return third;
82    }
83  
84    public void setThird(C third) {
85      this.third = third;
86    }
87  }
88  
89  
90