From: Roland Haeder Date: Fri, 11 Sep 2015 09:46:55 +0000 (+0200) Subject: updated jar + isAdded() cannot call contains() because the item instance is always... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=73b901e9d9e1638a493040c23f986df950b75d5d;p=jshop-core.git updated jar + isAdded() cannot call contains() because the item instance is always new. Instead it needs to check the (unique) item id. Signed-off-by:Roland Häder --- diff --git a/lib/jcore-ee-logger.jar b/lib/jcore-ee-logger.jar index 4edcfad..61710f1 100644 Binary files a/lib/jcore-ee-logger.jar and b/lib/jcore-ee-logger.jar differ diff --git a/src/org/mxchange/jshopcore/model/basket/BaseBasket.java b/src/org/mxchange/jshopcore/model/basket/BaseBasket.java index f510552..2a4de12 100644 --- a/src/org/mxchange/jshopcore/model/basket/BaseBasket.java +++ b/src/org/mxchange/jshopcore/model/basket/BaseBasket.java @@ -20,6 +20,7 @@ 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; /** @@ -113,7 +114,24 @@ public abstract class BaseBasket implements Basket< throw new NullPointerException("item is null"); //NOI18N } + // Get all items + Map map = this.getAll(); + + // Default is not found + boolean isAdded = false; + + for (Map.Entry entrySet : map.entrySet()) { + // Get item id + Long itemId = entrySet.getKey(); + + // Compare id + if (Objects.equals(itemId, item.getItemId())) { + // Okay, found it + isAdded = true; + break; + } + } // Return it - return this.deque.contains(item); + return isAdded; } } diff --git a/src/org/mxchange/jshopcore/model/basket/Basket.java b/src/org/mxchange/jshopcore/model/basket/Basket.java index 51f4a58..8e17339 100644 --- a/src/org/mxchange/jshopcore/model/basket/Basket.java +++ b/src/org/mxchange/jshopcore/model/basket/Basket.java @@ -37,8 +37,8 @@ public interface Basket extends Serializable { public void addItem (final T item) throws BasketItemAlreadyAddedException; /** - * Checks whether the given item as already been added. If the product's - * item id number was found in basket, the corresponding item instance will be set + * Checks whether the given item has already been added by checking the + * item's id. * * @param item Item instance to check * @return Whether the given item has been found