tuna-master/modelling/src/main/java/modelling/util/Pair.java
package modelling.util;

/**
 * A data structure to handle a pair of values
 *
 * @param <T> The type of the first value
 * @param <U> The type of the second value
 * @author neubig
 */
public class Pair<T, U> {

    private final T first;
    private final U second;
    private transient final int hash;

    public Pair(T f, U s) {
        this.first = f;
        this.second = s;
        hash = (first == null ? 0 : first.hashCode() * 31)
                + (second == null ? 0 : second.hashCode());
    }

    public T getFirst() {
        return first;
    }

    public U getSecond() {
        return second;
    }

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

    @SuppressWarnings("unchecked")
    @Override
    public boolean equals(Object oth) {
        if (this == oth) {
            return true;
        }
        if (oth == null || !(getClass().isInstance(oth))) {
            return false;
        }
        Pair<T, U> other = this.getClass().cast(oth);
        return (first == null ? other.first == null : first.equals(other.first))
                && (second == null ? other.second == null : second.equals(other.second));
    }
}