refactor: generated equals and hashcode for tuples

This commit is contained in:
Yannik Bretschneider 2021-06-06 03:20:58 +02:00
parent d45ad7d807
commit e9640a9a8a

View File

@ -1,5 +1,7 @@
package uulm.teamname.marvelous.gamelibrary;
import java.util.Objects;
/** Represents a pair of two objects. */
public class Tuple<X, Y> {
public final X item1;
@ -14,4 +16,25 @@ public class Tuple<X, Y> {
public static <X, Y> Tuple<X, Y> of(X x, Y y) {
return new Tuple<X, Y>(x, 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(item1, tuple.item1) && Objects.equals(item2, tuple.item2);
}
@Override
public int hashCode() {
return Objects.hash(item1, item2);
}
@Override
public String toString() {
return "Tuple{" +
"item1=" + item1 +
", item2=" + item2 +
'}';
}
}