]> git.mxchange.org Git - jshop-core.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Mon, 14 Sep 2015 08:40:29 +0000 (10:40 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 14 Sep 2015 08:40:29 +0000 (10:40 +0200)
- added method isProductType()
- changed type of getAll() to List asthis is fine
- updated jars
Signed-off-by:Roland Häder <roland@mxchange.org>

lib/jcore-ee-logger.jar
lib/jcoreee.jar
src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java
src/org/mxchange/jshopcore/model/basket/BaseBasket.java
src/org/mxchange/jshopcore/model/basket/Basket.java
src/org/mxchange/jshopcore/model/item/BaseItem.java

index 6d0e98ca34bb9da22fe71b465ba1765a785a8053..9631578315fa23cab8f95f90e90b3013588b16ea 100644 (file)
Binary files a/lib/jcore-ee-logger.jar and b/lib/jcore-ee-logger.jar differ
index 925c0588c2c33478379c56e9a328d3a9772393b1..20252ca040b5e56afe2e392067112c8f883da4a8 100644 (file)
Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ
index 24997a8621ef99eec586451c07588f649d00a7a1..163eefd691cbb2832ebfb2e046e69120f0082101 100644 (file)
@@ -95,4 +95,11 @@ public interface AddableBasketItem extends Serializable {
         * @param product the product to set
         */
        public void setProduct (final Product product);
+
+       /**
+        * Determines whether the item has a Product instance set
+        *
+        * @return Whether a Product instance is set
+        */
+       public boolean isProductType ();
 }
index aac402052b9fa438db40707c612e4fe1e60864bd..06755b11078997f6692976dc6f154f24f4b518ce 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,9 +69,9 @@ 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) {
@@ -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
index 8e173391725b00d9d6438df7b55aa64922f7cbbc..f0824bb474d9ff04e12c17d89249f101cb13e989 100644 (file)
@@ -17,7 +17,7 @@
 package org.mxchange.jshopcore.model.basket;
 
 import java.io.Serializable;
-import java.util.Map;
+import java.util.List;
 import org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException;
 
 /**
@@ -57,7 +57,7 @@ public interface Basket<T extends AddableBasketItem> extends Serializable {
         *
         * @return Map on all basket items
         */
-       public Map<Long, T> getAll ();
+       public List<T> getAll ();
 
        /**
         * Getter for last entry
index 2015d2dd1c09f925f0e70af6634ba7564e4af945..8e4591e6b64d9cef1b9c54f8aa1d78806c7a66bb 100644 (file)
@@ -154,4 +154,10 @@ public abstract class BaseItem implements AddableBasketItem, Comparable<AddableB
                hash = 29 * hash + Objects.hashCode(this.getItemType());
                return hash;
        }
+
+       @Override
+       public boolean isProductType () {
+               // Is the instance set?
+               return (this.getProduct() instanceof Product);
+       }
 }