From 035bf2eb7cfe9d50e031291946fed9b216b977bd Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Fri, 21 May 2021 14:16:02 +0200 Subject: [PATCH] refactor: generated Equals and HashCode for requests where necessary --- .../gamelibrary/requests/CharacterRequest.java | 16 ++++++++++++++++ .../gamelibrary/requests/GameRequest.java | 4 +--- .../marvelous/gamelibrary/requests/Request.java | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/CharacterRequest.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/CharacterRequest.java index 74632bc..6a37235 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/CharacterRequest.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/CharacterRequest.java @@ -4,6 +4,8 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.StoneType; +import java.util.Objects; + /** Represents a character event for: {@link RequestType#MeleeAttackRequest}, {@link RequestType#RangedAttackRequest}, {@link RequestType#MoveRequest}, {@link RequestType#ExchangeInfinityStoneRequest}, {@link RequestType#UseInfinityStoneRequest}. */ public class CharacterRequest extends Request { public EntityID originEntity = null; @@ -12,4 +14,18 @@ public class CharacterRequest extends Request { public IntVector2 targetField = null; public Integer value = null; //why is it called amount in events and value in requests? public StoneType stoneType = null; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + CharacterRequest that = (CharacterRequest) o; + return Objects.equals(originEntity, that.originEntity) && Objects.equals(targetEntity, that.targetEntity) && Objects.equals(originField, that.originField) && Objects.equals(targetField, that.targetField) && Objects.equals(value, that.value) && stoneType == that.stoneType; + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), originEntity, targetEntity, originField, targetField, value, stoneType); + } } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/GameRequest.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/GameRequest.java index 4a9a5bc..b37e36b 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/GameRequest.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/GameRequest.java @@ -1,6 +1,4 @@ package uulm.teamname.marvelous.gamelibrary.requests; /** Represents a game request for: {@link RequestType#DisconnectRequest}. */ -public class GameRequest extends Request { - -} +public class GameRequest extends Request {} diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/Request.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/Request.java index ffbc8a8..82f6adf 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/Request.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/requests/Request.java @@ -2,7 +2,23 @@ package uulm.teamname.marvelous.gamelibrary.requests; import uulm.teamname.marvelous.gamelibrary.json.ingame.MessageStructure; +import java.util.Objects; + /** Represents an abstract request sent inside a {@link MessageStructure} between client and server. */ public abstract class Request { public RequestType type; + + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Request request = (Request) o; + return type == request.type; + } + + @Override + public int hashCode() { + return Objects.hash(type); + } }