fix: generated equals and hashCode for events, entities and entityIDs
This commit is contained in:
@ -2,6 +2,8 @@ package uulm.teamname.marvelous.gamelibrary.entities;
|
||||
|
||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/** Represents an abstract entity. */
|
||||
public abstract class Entity {
|
||||
/** Whether or not the entity is currently active in the game */
|
||||
@ -44,5 +46,18 @@ public abstract class Entity {
|
||||
public void setPosition(IntVector2 position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Entity entity = (Entity) o;
|
||||
return active == entity.active && Objects.equals(position, entity.position) && Objects.equals(id, entity.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(active, position, id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.entities;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/** Represents a distinct identification for every {@link Entity} in a game. */
|
||||
public class EntityID {
|
||||
/** The index of the entity */
|
||||
@ -42,4 +44,18 @@ public class EntityID {
|
||||
public String toString() {
|
||||
return "["+type.toString()+":"+id+"]";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
EntityID entityID = (EntityID) o;
|
||||
return id == entityID.id && type == entityID.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, type);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user