import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
-import java.util.Objects;
import org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException;
/**
boolean isAdded = false;
for (Map.Entry<Long, T> 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;
public void setProduct (final Product product) {
this.product = product;
}
+
+ @Override
+ public boolean equals (final Object object) {
+ // Is it same type?
+ if (!(object instanceof BaseItem)) {
+ // Not equal types
+ return false;
+ } else if (!(object instanceof AddableBasketItem)) {
+ // Not correct interface
+ return false;
+ }
+
+ // Securely cast to wanted interface
+ AddableBasketItem item = (AddableBasketItem) object;
+
+ // Item id and type must be the same
+ return ((Objects.equals(item.getItemId(), this.getItemId()))
+ && (Objects.equals(item.getItemType(), this.getItemType())));
+ }
+
+ @Override
+ public int hashCode () {
+ int hash = 5;
+ hash = 29 * hash + Objects.hashCode(this.getItemId());
+ hash = 29 * hash + Objects.hashCode(this.getItemType());
+ return hash;
+ }
}