001/**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020package org.apache.hadoop.hbase.util;
021
022import org.apache.yetus.audience.InterfaceAudience;
023
024/**
025 *  A generic class for pair of an Object and and a primitive int value.
026 */
027@InterfaceAudience.Private
028public class ObjectIntPair<T> {
029
030  private T first;
031  private int second;
032
033  public ObjectIntPair() {
034  }
035
036  public ObjectIntPair(T first, int second) {
037    this.setFirst(first);
038    this.setSecond(second);
039  }
040
041  public T getFirst() {
042    return first;
043  }
044
045  public void setFirst(T first) {
046    this.first = first;
047  }
048
049  public int getSecond() {
050    return second;
051  }
052
053  public void setSecond(int second) {
054    this.second = second;
055  }
056
057  @Override
058  public boolean equals(Object other) {
059    return other instanceof ObjectIntPair && equals(first, ((ObjectIntPair<?>) other).first)
060        && (this.second == ((ObjectIntPair<?>) other).second);
061  }
062
063  private static boolean equals(Object x, Object y) {
064    return (x == null && y == null) || (x != null && x.equals(y));
065  }
066
067  @Override
068  public int hashCode() {
069    return first == null ? 0 : (first.hashCode() * 17) + 13 * second;
070  }
071
072  @Override
073  public String toString() {
074    return "{" + getFirst() + "," + getSecond() + "}";
075  }
076}