refactor: generated Equals and HashCode for requests where necessary

This commit is contained in:
Yannik Bretschneider 2021-05-21 14:16:02 +02:00
parent 596ace355a
commit 035bf2eb7c
3 changed files with 33 additions and 3 deletions

View File

@ -4,6 +4,8 @@ import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
import uulm.teamname.marvelous.gamelibrary.entities.StoneType; 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}. */ /** 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 class CharacterRequest extends Request {
public EntityID originEntity = null; public EntityID originEntity = null;
@ -12,4 +14,18 @@ public class CharacterRequest extends Request {
public IntVector2 targetField = null; public IntVector2 targetField = null;
public Integer value = null; //why is it called amount in events and value in requests? public Integer value = null; //why is it called amount in events and value in requests?
public StoneType stoneType = null; 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);
}
} }

View File

@ -1,6 +1,4 @@
package uulm.teamname.marvelous.gamelibrary.requests; package uulm.teamname.marvelous.gamelibrary.requests;
/** Represents a game request for: {@link RequestType#DisconnectRequest}. */ /** Represents a game request for: {@link RequestType#DisconnectRequest}. */
public class GameRequest extends Request { public class GameRequest extends Request {}
}

View File

@ -2,7 +2,23 @@ package uulm.teamname.marvelous.gamelibrary.requests;
import uulm.teamname.marvelous.gamelibrary.json.ingame.MessageStructure; 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. */ /** Represents an abstract request sent inside a {@link MessageStructure} between client and server. */
public abstract class Request { public abstract class Request {
public RequestType type; 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);
}
} }