]> git.mxchange.org Git - jcustomer-core.git/blobdiff - src/org/mxchange/jshopcore/model/basket/BaseBasket.java
use final where possible
[jcustomer-core.git] / src / org / mxchange / jshopcore / model / basket / BaseBasket.java
index aac402052b9fa438db40707c612e4fe1e60864bd..bf476b98744f2d6defe599ac87e3d0b45d83b8d7 100644 (file)
@@ -17,9 +17,8 @@
 package org.mxchange.jshopcore.model.basket;
 
 import java.util.Deque;
-import java.util.LinkedHashMap;
 import java.util.LinkedList;
-import java.util.Map;
+import java.util.List;
 import org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException;
 
 /**
@@ -70,12 +69,12 @@ public abstract class BaseBasket<T extends AddableBasketItem> implements Basket<
        }
 
        @Override
-       public Map<Long, T> getAll () {
+       public List<T> getAll () {
                // Init map
-               Map<Long, T> map = new LinkedHashMap<>(this.deque.size());
+               List<T> list = new LinkedList<>();
 
                // Iterate over full item list
-               for (T item : this.deque) {
+               for (final T item : this.deque) {
                        // item should not be null
                        if (null == item) {
                                // Abort here
@@ -83,11 +82,11 @@ public abstract class BaseBasket<T extends AddableBasketItem> implements Basket<
                        }
 
                        // Add to map, use the item's id as key
-                       map.put(item.getItemId(), item);
+                       list.add(item);
                }
 
                // Return it
-               return map;
+               return list;
        }
 
        @Override
@@ -114,15 +113,13 @@ public abstract class BaseBasket<T extends AddableBasketItem> implements Basket<
                }
 
                // Get all items
-               Map<Long, T> map = this.getAll();
+               List<T> list = this.getAll();
 
                // Default is not found
                boolean isAdded = false;
 
-               for (Map.Entry<Long, T> entrySet : map.entrySet()) {
-                       // Get whole item
-                       T i = entrySet.getValue();
-
+               // Loop through list
+               for (final T i : list) {
                        // Compare id
                        if (i.equals(item)) {
                                // Okay, found it
@@ -133,4 +130,10 @@ public abstract class BaseBasket<T extends AddableBasketItem> implements Basket<
                // Return it
                return isAdded;
        }
+
+       @Override
+       public void clear () {
+               // Deligate to deque
+               this.deque.clear();
+       }
 }