package cs451.tools;

import java.util.ArrayList;
import java.util.List;

/**
 * Pair Class used in many scenarios of NEHs
 * @param <S>
 * @param <T>
 */
public class Pair<S, T> implements  Comparable<T> {

    private final List<Object> vl = new ArrayList<>();

    public Pair(S x, T y) {
        vl.add(x);
        vl.add(y);
    }

    @SuppressWarnings("unchecked")
    public S first(){
        return (S) vl.get(0);
    }

    @SuppressWarnings("unchecked")
    public T second(){
        return (T) vl.get(1);
    }

    public void first(S v){
        vl.set(0,v);
    }

    public void second(T v){
        vl.set(1,v);
    }


    @Override
    public final String toString() {
        return this.vl.toString();
    }

    @Override
    public int hashCode() {
        return this.vl.hashCode();
    }

    @Override
    @SuppressWarnings("unchecked")
    public final boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Pair<S,T> other = (Pair<S,T>) obj;
        return  this.first().equals(other.first()) && this.second().equals(other.second());
    }

    @Override
    @SuppressWarnings("unchecked")
    public int compareTo(Object o) {
        Pair<S,T> co = (Pair<S,T>)o;
        return ((Comparable<T>)second()).compareTo(co.second());
    }
}
