From 5aed37f8e1a21fcea34fd17f2f547479da359d0a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 11 Sep 2015 11:53:09 +0200 Subject: [PATCH] =?utf8?q?Added=20equals()=20and=20hashCode()=20for=20easy?= =?utf8?q?=20item=20comparison.=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../jshopcore/model/basket/BaseBasket.java | 7 +++-- .../jshopcore/model/item/BaseItem.java | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/org/mxchange/jshopcore/model/basket/BaseBasket.java b/src/org/mxchange/jshopcore/model/basket/BaseBasket.java index 2a4de12..aac4020 100644 --- a/src/org/mxchange/jshopcore/model/basket/BaseBasket.java +++ b/src/org/mxchange/jshopcore/model/basket/BaseBasket.java @@ -20,7 +20,6 @@ import java.util.Deque; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.Map; -import java.util.Objects; import org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException; /** @@ -121,11 +120,11 @@ public abstract class BaseBasket implements Basket< boolean isAdded = false; for (Map.Entry entrySet : map.entrySet()) { - // Get item id - Long itemId = entrySet.getKey(); + // Get whole item + T i = entrySet.getValue(); // Compare id - if (Objects.equals(itemId, item.getItemId())) { + if (i.equals(item)) { // Okay, found it isAdded = true; break; diff --git a/src/org/mxchange/jshopcore/model/item/BaseItem.java b/src/org/mxchange/jshopcore/model/item/BaseItem.java index 7a8d50c..2015d2d 100644 --- a/src/org/mxchange/jshopcore/model/item/BaseItem.java +++ b/src/org/mxchange/jshopcore/model/item/BaseItem.java @@ -127,4 +127,31 @@ public abstract class BaseItem implements AddableBasketItem, Comparable