/**
* Copyright (C) 2013-2014 Olaf Lessenich
* Copyright (C) 2014-2015 University of Passau, Germany
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* Contributors:
* Olaf Lessenich <lessenic@fim.uni-passau.de>
* Georg Seibt <seibt@fim.uni-passau.de>
*/
package de.fosd.jdime.util;
import java.util.Objects;
/**
* A generic tuple.
*
* @param <X>
* type of first element
* @param <Y>
* type of second element
* @author Olaf Lessenich
*/
public class Tuple<X, Y> {
public final X x;
public final Y y;
private Tuple(X x, Y y) {
this.x = x;
this.y = y;
}
public static <X, Y> Tuple<X, Y> of(X x, Y y) {
return new Tuple<>(x, y);
}
/**
* Returns the first object contained in the <code>Tuple</code>.
*
* @return the first object
*/
public X getX() {
return x;
}
/**
* Returns the second object contained in the <code>Tuple</code>.
*
* @return the second object
*/
public Y getY() {
return y;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Tuple<?, ?> tuple = (Tuple<?, ?>) o;
return Objects.equals(x, tuple.x) && Objects.equals(y, tuple.y);
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
}