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 * A generic class for pair of an Object and and a primitive int value.
024 */
025@InterfaceAudience.Private
026public class ObjectIntPair<T> {
027
028  private T first;
029  private int second;
030
031  public ObjectIntPair() {
032  }
033
034  public ObjectIntPair(T first, int second) {
035    this.setFirst(first);
036    this.setSecond(second);
037  }
038
039  public T getFirst() {
040    return first;
041  }
042
043  public void setFirst(T first) {
044    this.first = first;
045  }
046
047  public int getSecond() {
048    return second;
049  }
050
051  public void setSecond(int second) {
052    this.second = second;
053  }
054
055  @Override
056  public boolean equals(Object other) {
057    return other instanceof ObjectIntPair && equals(first, ((ObjectIntPair<?>) other).first)
058      && (this.second == ((ObjectIntPair<?>) other).second);
059  }
060
061  private static boolean equals(Object x, Object y) {
062    return (x == null && y == null) || (x != null && x.equals(y));
063  }
064
065  @Override
066  public int hashCode() {
067    return first == null ? 0 : (first.hashCode() * 17) + 13 * second;
068  }
069
070  @Override
071  public String toString() {
072    return "{" + getFirst() + "," + getSecond() + "}";
073  }
074}