/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.accumulo.core.util;

import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map.Entry;

public class Pair<A,B> {
  A first;
  B second;

  public Pair(A f, B s) {
    this.first = f;
    this.second = s;
  }

  private int hashCode(Object o) {
    if (o == null)
      return 0;
    return o.hashCode();
  }

  @Override
  public int hashCode() {
    return hashCode(first) + hashCode(second);
  }

  private boolean equals(Object o1, Object o2) {
    if (o1 == null || o2 == null)
      return o1 == o2;

    return o1.equals(o2);
  }

  @Override
  public boolean equals(Object o) {
    if (o instanceof Pair<?,?>) {
      Pair<?,?> op = (Pair<?,?>) o;
      return equals(first, op.first) && equals(second, op.second);
    }
    return false;
  }

  public A getFirst() {
    return first;
  }

  public B getSecond() {
    return second;
  }

  @Override
  public String toString() {
    return toString("(", ",", ")");
  }

  public String toString(String prefix, String separator, String suffix) {
    return prefix + first + separator + second + suffix;
  }

  public Entry<? super A,? super B> toMapEntry() {
    return new SimpleImmutableEntry<A,B>(getFirst(), getSecond());
  }

  public Pair<? super B,? super A> swap() {
    return new Pair<B,A>(getSecond(), getFirst());
  }

  public static <K2,V2,K1 extends K2,V1 extends V2> Pair<K2,V2> fromEntry(Entry<K1,V1> entry) {
    return new Pair<K2,V2>(entry.getKey(), entry.getValue());
  }

}

@@ -1912,26 +1912,10 @@
 try%3C
-? super A,? super 
+A,
 B%3E t
@@ -2018,26 +2018,10 @@
 air%3C
-? super B,? super 
+B,
 A%3E s
@@ -2106,48 +2106,18 @@
 c %3CK
-2,V2,K1 extends K2,V1 extends V2
+,V
 %3E Pair%3CK
 2,V2
@@ -2112,20 +2112,18 @@
 %3E Pair%3CK
-2
 ,V
-2
 %3E fromEn
@@ -2137,12 +2137,10 @@
 ry%3CK
-1
 ,V
-1
 %3E en
@@ -2171,12 +2171,10 @@
 ir%3CK
-2
 ,V
-2
 %3E(en

Revert "ACCUMULO-2490 Make Pair API more generics-friendly"