import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
+import java.util.Objects;
import org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException;
/**
throw new NullPointerException("item is null"); //NOI18N
}
+ // Get all items
+ Map<Long, T> map = this.getAll();
+
+ // Default is not found
+ boolean isAdded = false;
+
+ for (Map.Entry<Long, T> 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;
}
}
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