From e9640a9a8a19b6c6cf9fea286c2c803e2cea8f5e Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Sun, 6 Jun 2021 03:20:58 +0200 Subject: [PATCH] refactor: generated equals and hashcode for tuples --- .../teamname/marvelous/gamelibrary/Tuple.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/Tuple.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/Tuple.java index ee66660..7dcb529 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/Tuple.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/Tuple.java @@ -1,5 +1,7 @@ package uulm.teamname.marvelous.gamelibrary; +import java.util.Objects; + /** Represents a pair of two objects. */ public class Tuple { public final X item1; @@ -14,4 +16,25 @@ public class Tuple { public static Tuple of(X x, Y y) { return new Tuple(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 + + '}'; + } }