package com.jscape.util;

/**
 * @author Alex Usun
 */
public final class Pair<F, S> {

    public F first;
    public S second;

    public static <F, S> Pair<F, S> pair(F first, S second) {
        return new Pair<F, S>(first, second);
    }

    public static <F> Pair<F, F> pair(F value) {
        return pair(value, value);
    }

    public Pair(F first, S second) {
        this.first = first;
        this.second = second;
    }

    public Pair() {
        this(null, null);
    }

    public F getFirst() {
        return this.first;
    }

    public void setFirst(F value) {
        this.first = value;
    }

    public S getSecond() {
        return this.second;
    }

    public void setSecond(S value) {
        this.second = value;
    }

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

        Pair<S, F> that = (Pair<S, F>) o;

        if (first != null ? !first.equals(that.first) : that.first != null) {
            return false;
        }

        if (second != null ? !second.equals(that.second) : that.second != null) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result = first != null ? first.hashCode() : 0;
        result = 31 * result + (second != null ? second.hashCode() : 0);
        return result;
    }

    public String toString() {
        return "Pair {"
                + "first=" + this.first
                + ", second=" + this.second
                + '}';
    }
}
