001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.util;
019
020import org.apache.yetus.audience.InterfaceAudience;
021
022/**
023 * Utility class to manage a triple.
024 */
025@InterfaceAudience.Private
026public class Triple<A, B, C> {
027  private A first;
028  private B second;
029  private C third;
030
031  // default constructor
032  public Triple() {
033
034  }
035
036  public Triple(A first, B second, C third) {
037    this.first = first;
038    this.second = second;
039    this.third = third;
040  }
041
042  // ctor cannot infer types w/o warning but a method can.
043  public static <A, B, C> Triple<A, B, C> create(A first, B second, C third) {
044    return new Triple<>(first, second, third);
045  }
046
047  @Override
048  public int hashCode() {
049    int hashFirst = (first != null ? first.hashCode() : 0);
050    int hashSecond = (second != null ? second.hashCode() : 0);
051    int hashThird = (third != null ? third.hashCode() : 0);
052
053    return (hashFirst >> 1) ^ hashSecond ^ (hashThird << 1);
054  }
055
056  @Override
057  public boolean equals(Object obj) {
058    if (!(obj instanceof Triple)) {
059      return false;
060    }
061
062    Triple<?, ?, ?> otherTriple = (Triple<?, ?, ?>) obj;
063
064    if (first != otherTriple.first && (first != null && !first.equals(otherTriple.first)))
065      return false;
066    if (second != otherTriple.second && (second != null && !second.equals(otherTriple.second)))
067      return false;
068    if (third != otherTriple.third && (third != null && !third.equals(otherTriple.third)))
069      return false;
070
071    return true;
072  }
073
074  @Override
075  public String toString() {
076    return "(" + first + ", " + second + "," + third + " )";
077  }
078
079  public A getFirst() {
080    return first;
081  }
082
083  public void setFirst(A first) {
084    this.first = first;
085  }
086
087  public B getSecond() {
088    return second;
089  }
090
091  public void setSecond(B second) {
092    this.second = second;
093  }
094
095  public C getThird() {
096    return third;
097  }
098
099  public void setThird(C third) {
100    this.third = third;
101  }
102}