From 09b631e0e07c7fc729a0c5bcb34e57892007b042 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 12 Jan 2018 00:33:53 +0100 Subject: Implement equality check Signed-off-by: pacien --- src/main/java/fr/umlv/java/wallj/model/Block.java | 15 +++++++++++++++ src/main/java/fr/umlv/java/wallj/model/BombBlock.java | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'src/main/java/fr/umlv') diff --git a/src/main/java/fr/umlv/java/wallj/model/Block.java b/src/main/java/fr/umlv/java/wallj/model/Block.java index 7f32087..25265d1 100644 --- a/src/main/java/fr/umlv/java/wallj/model/Block.java +++ b/src/main/java/fr/umlv/java/wallj/model/Block.java @@ -72,4 +72,19 @@ public abstract class Block { .collect(Collectors.toList()); } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Block)) return false; + Block block = (Block) o; + return type == block.type && + Objects.equals(controllers, block.controllers) && + Objects.equals(pos, block.pos); + } + + @Override + public int hashCode() { + return Objects.hash(type, controllers, pos); + } + } diff --git a/src/main/java/fr/umlv/java/wallj/model/BombBlock.java b/src/main/java/fr/umlv/java/wallj/model/BombBlock.java index 9ba4a68..4eca843 100644 --- a/src/main/java/fr/umlv/java/wallj/model/BombBlock.java +++ b/src/main/java/fr/umlv/java/wallj/model/BombBlock.java @@ -2,6 +2,8 @@ package fr.umlv.java.wallj.model; import org.jbox2d.common.Vec2; +import java.util.Objects; + /** * A bomb block. * @@ -25,4 +27,19 @@ public class BombBlock extends Block { return timer; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof BombBlock)) return false; + if (!super.equals(o)) return false; + BombBlock bombBlock = (BombBlock) o; + return timer == bombBlock.timer && + super.equals(o); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), timer); + } + } -- cgit v1.2.3