/*
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.generic;

import lombok.Data;

import java.io.Serializable;

/**
 * Represents immutable pair of values.
 * It implements Comparable and can be used as a key inside any Map.
 *
 * It uses {@linkplain CompareUtils#comparator() natural comparator} to compare values.
 *
 * @param <P> P
 * @param <Q> Q
 */
@Data(staticConstructor = "of")
public final class Pair<P,Q> implements Comparable<Pair<P,Q>>, Serializable {

    private static final long serialVersionUID = 1L;

    private final P first;
    private final Q second;

    @Override
    public int compareTo(Pair<P, Q> that) {
        int cmp1 = CompareUtils.cmp(this.first, that.first);
        return cmp1 != 0 ? cmp1 : CompareUtils.cmp(this.second, that.second);
    }

}
