/* This file is part of VoltDB.
 * Copyright (C) 2008-2013 VoltDB Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with VoltDB.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.voltcore.utils;

/**
 * Class representing a pair of generic-ized types. Supports equality, hashing
 * and all that other nice Java stuff. Based on STL's pair class in C++.
 *
 */
public class Pair<T, U> {
    protected final T m_first;
    protected final U m_second;
    protected transient final int m_hash;

    public Pair(T first, U second) {
        m_first = first;
        m_second = second;
        m_hash = (first == null ? 0 : first.hashCode() * 31) +
                (second == null ? 0 : second.hashCode());
    }

    @Override
    public String toString() {
        return "<" + m_first.toString() + ", " + m_second.toString() + ">";
    }

    @Override
    public int hashCode() {
        return m_hash;
    }

    public Object get(int idx) {
        if (idx == 0) return m_first;
        else if (idx == 1) return m_second;
        return null;
    }

    /**
     * @param o Object to compare to.
     * @return Is the object equal to a value in the pair.
     */
    public boolean contains(Object o) {
        if ((m_first != null) && (m_first.equals(o))) return true;
        if ((m_second != null) && (m_second.equals(o))) return true;
        if (o != null) return false;
        return ((m_first == null) || (m_second == null));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || !(getClass().isInstance(o))) {
            return false;
        }

        @SuppressWarnings("unchecked")
        Pair<T, U> other = (Pair<T, U>) o;

        return (m_first == null ? other.m_first == null : m_first.equals(other.m_first)) &&
               (m_second == null ? other.m_second == null : m_second.equals(other.m_second));
    }

    /**
     * @return the first
     */
    public T getFirst() {
        return m_first;
    }

    /**
     * @return the second
     */
    public U getSecond() {
        return m_second;
    }

    /**
     * Convenience class method for constructing pairs using Java's generic type
     * inference.
     */
    public static <T, U> Pair<T, U> of(T x, U y) {
        return new Pair<T, U>(x, y);
    }
}

@@ -1090,16 +1090,36 @@
 U second
+, final boolean hash
 ) %7B%0A    
@@ -1158,32 +1158,56 @@
 econd = second;%0A
+        if (hash) %7B%0A    
         m_hash =
@@ -1254,11 +1254,14 @@
  31)
- +%0A
+%0A     
     
@@ -1271,16 +1271,17 @@
         
++
  (second
@@ -1319,32 +1319,148 @@
 ));%0A    
-%7D%0A%0A    @Override
+    %7D else %7B%0A            m_hash = 0;%0A        %7D%0A    %7D%0A%0A    public Pair(T first, U second) %7B%0A        this(first, second, true);%0A    %7D%0A
 %0A    pub
@@ -1562,38 +1562,24 @@
 %22%3E%22;%0A    %7D%0A%0A
-    @Override%0A
     public i
@@ -2162,22 +2162,8 @@
  %7D%0A%0A
-    @Override%0A
     

Revert changes to Pair.java -- still needed in pro code.