refactor: generated equals and hashcode for tuples
This commit is contained in:
parent
d45ad7d807
commit
e9640a9a8a
@ -1,5 +1,7 @@
|
|||||||
package uulm.teamname.marvelous.gamelibrary;
|
package uulm.teamname.marvelous.gamelibrary;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/** Represents a pair of two objects. */
|
/** Represents a pair of two objects. */
|
||||||
public class Tuple<X, Y> {
|
public class Tuple<X, Y> {
|
||||||
public final X item1;
|
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) {
|
public static <X, Y> Tuple<X, Y> of(X x, Y y) {
|
||||||
return new Tuple<X, Y>(x, 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 +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user