]> git.mxchange.org Git - jshop-core.git/commitdiff
Updated author (email address) + jars + implemented very basic basket
authorRoland Haeder <roland@mxchange.org>
Thu, 10 Sep 2015 13:39:44 +0000 (15:39 +0200)
committerRoland Haeder <roland@mxchange.org>
Thu, 10 Sep 2015 13:39:44 +0000 (15:39 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

19 files changed:
lib/jcore-ee-logger.jar
lib/jcoreee.jar
src/org/mxchange/jshopcore/exceptions/BasketItemAlreadyAddedException.java [new file with mode: 0644]
src/org/mxchange/jshopcore/exceptions/CategoryTitleAlreadyUsedException.java
src/org/mxchange/jshopcore/exceptions/ProductTitleAlreadyUsedException.java
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/basket/ShopBasket.java
src/org/mxchange/jshopcore/model/category/BaseCategory.java
src/org/mxchange/jshopcore/model/category/Category.java
src/org/mxchange/jshopcore/model/category/ProductCategory.java
src/org/mxchange/jshopcore/model/customer/Customer.java
src/org/mxchange/jshopcore/model/customer/ShopCustomer.java
src/org/mxchange/jshopcore/model/item/BaseItem.java
src/org/mxchange/jshopcore/model/item/BasketItem.java
src/org/mxchange/jshopcore/model/product/BaseProduct.java
src/org/mxchange/jshopcore/model/product/GenericProduct.java
src/org/mxchange/jshopcore/model/product/Product.java

index 5ebf6d07bb973bde224c28c9e8403af3719390fe..c65212243809f11f3ffb24a9b60a199155e03c07 100644 (file)
Binary files a/lib/jcore-ee-logger.jar and b/lib/jcore-ee-logger.jar differ
index 963ff769842e10dc653a66a7c0a12233947fe660..935a2c95c4a2c3876bdb5fbc0aa3c28141edb024 100644 (file)
Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ
diff --git a/src/org/mxchange/jshopcore/exceptions/BasketItemAlreadyAddedException.java b/src/org/mxchange/jshopcore/exceptions/BasketItemAlreadyAddedException.java
new file mode 100644 (file)
index 0000000..efd2492
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2015 Roland Haeder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jshopcore.exceptions;
+
+import java.text.MessageFormat;
+import org.mxchange.jshopcore.model.basket.AddableBasketItem;
+
+/**
+ * An exception thrown when the given item is already added to the basket.
+ *
+ * @author Roland Haeder
+ */
+public class BasketItemAlreadyAddedException extends Exception {
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 64_828_391_485_785_167L;
+
+       /**
+        * Constructor with item instance T
+        *
+        * @param <T> Any item that is or extends the interface
+        * @param item An instance of a T item
+        */
+       public <T extends AddableBasketItem>BasketItemAlreadyAddedException (final T item) {
+               // Create message and pass it along
+               super(MessageFormat.format("Item {0} has already been added. Did you miss to call isAdded()?", item));
+       }
+}
index 4936d6520ebbb5bc4481e600d0fde2e80323de2e..fa290f4819f9f473a70c8cab62fc611561b7394c 100644 (file)
@@ -22,7 +22,7 @@ import org.mxchange.jshopcore.model.category.Category;
 /**
  * An exception thrown when the given title is already used
  * 
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public class CategoryTitleAlreadyUsedException extends Exception {
        /**
@@ -39,4 +39,14 @@ public class CategoryTitleAlreadyUsedException extends Exception {
                // Call super constructor
                super(MessageFormat.format("Title {0} is already used.", category.getTitle())); //NOI18N
        }
+
+       /**
+        * Constructor with HttpServletRequest instance
+        *
+        * @param cause Cause for this exception
+        */
+       public CategoryTitleAlreadyUsedException (final Throwable cause) {
+               // Call super constructor
+               super(cause);
+       }
 }
index 319164638576223cb0a656a930166a580b73b9a0..53ec406389c1f34bf78dde57397581b3f16f3182 100644 (file)
@@ -22,7 +22,7 @@ import org.mxchange.jshopcore.model.product.Product;
 /**
  * An exception thrown when the given title is already used
  * 
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public class ProductTitleAlreadyUsedException extends Exception {
        /**
@@ -39,4 +39,14 @@ public class ProductTitleAlreadyUsedException extends Exception {
                // Call super constructor
                super(MessageFormat.format("Title {0} is already used.", product.getTitle())); //NOI18N
        }
+
+       /**
+        * Constructor with HttpServletRequest instance
+        *
+        * @param cause Cause for this exception
+        */
+       public ProductTitleAlreadyUsedException (final Throwable cause) {
+               // Call super constructor
+               super(cause); //NOI18N
+       }
 }
index db0855ae5296091b0a9e33140f6b3dc5755ae19b..24997a8621ef99eec586451c07588f649d00a7a1 100644 (file)
@@ -22,66 +22,76 @@ import org.mxchange.jshopcore.model.product.Product;
 /**
  * An interface for addable basket items
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public interface AddableBasketItem extends Serializable {
 
        /**
-        * Item amount
+        * Getter for item amount
         *
         * @return the amount
         */
        public Long getAmount ();
 
        /**
-        * Item amount
+        * Setter for item amount
         *
         * @param amount the amount to set
         */
        public void setAmount (final Long amount);
 
        /**
-        * Entry id (from database backend)
+        * Getter for entry id (from database backend)
         *
         * @return the id
         */
        public Long getId ();
 
        /**
-        * Entry id (from database backend)
+        * Setter for entry id (from database backend)
         *
         * @param id the id to set
         */
        public void setId (final Long id);
 
        /**
+        * Getter for item id (e.g. from product)
+        *
         * @return the id
         */
        public Long getItemId ();
 
        /**
+        * Setter for item id (e.g. from product)
+        *
         * @param id the id to set
         */
        public void setItemId (final Long id);
 
        /**
+        * Getter for item type
+        *
         * @return the type
         */
        public String getItemType ();
 
        /**
+        * Setter for item type
+        *
         * @param type the type to set
         */
        public void setItemType (final String type);
 
        /**
+        * Getter for product instance
+        *
         * @return the product
         */
        public Product getProduct ();
 
        /**
-        * Product instance
-        * 
+        * Setter fo product instance
+        *
         * @param product the product to set
         */
        public void setProduct (final Product product);
index 54ac27660a0e4b13d05c82669272742b92709a34..f51055203f97a9e5098f3363f9943f93c1e367d9 100644 (file)
  */
 package org.mxchange.jshopcore.model.basket;
 
+import java.util.Deque;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
 import java.util.Map;
+import org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException;
 
 /**
  * A general basket class. This class does not store any properties, it only
  * contains logic for handling the items (T).
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  * @param <T> Any instance that implements AddableBasketItem
  */
 public abstract class BaseBasket<T extends AddableBasketItem> implements Basket<T> {
@@ -31,43 +35,56 @@ public abstract class BaseBasket<T extends AddableBasketItem> implements Basket<
         */
        private static final long serialVersionUID = 782_396_762_230_845_717L;
 
+       /**
+        * Ordered item list
+        */
+       private final Deque<T> deque;
+
        /**
         * Protected constructor with session instance
         */
        protected BaseBasket () {
+               // Init queue
+               this.deque = new LinkedList<>();
        }
 
        @Override
-       public void init () {
-       }
-
-       @Override
-       public void addItem (final T item) {
+       public void addItem (final T item) throws BasketItemAlreadyAddedException {
                // item must not be null
                if (null == item) {
                        // Then abort here
                        throw new NullPointerException("item is null"); //NOI18N
                } else if (this.isAdded(item)) {
                        // Already been added
-                       throw new IllegalArgumentException("item has already been added. Did you miss to call isAdded()?"); //NOI18N
+                       throw new BasketItemAlreadyAddedException(item); //NOI18N
                }
 
-               // Add item to database
-               // TODO: ((BasketFrontend) this.getFrontend()).addItem(item, this.getSessionId());
+               // Add it here
+               this.deque.add(item);
        }
 
        @Override
        public boolean isEmpty () {
                // Deligate call to frontend
-               // TODO: return ((BasketFrontend) this.getFrontend()).isEmpty();
-               throw new UnsupportedOperationException("Not yet implmeneted.");
+               return this.deque.isEmpty();
        }
 
        @Override
        public Map<Long, T> getAll () {
                // Init map
-               // TODO: Map<Long, T> map = ((BasketFrontend) this.getFrontend()).getAll();
-               Map<Long, T> map = null;
+               Map<Long, T> map = new LinkedHashMap<>(this.deque.size());
+
+               // Iterate over full item list
+               for (T item : this.deque) {
+                       // item should not be null
+                       if (null == item) {
+                               // Abort here
+                               throw new NullPointerException("item is null"); //NOI18N
+                       }
+
+                       // Add to map, use the item's id as key
+                       map.put(item.getItemId(), item);
+               }
 
                // Return it
                return map;
@@ -75,16 +92,17 @@ public abstract class BaseBasket<T extends AddableBasketItem> implements Basket<
 
        @Override
        public T getLast () {
-               // Deligate to frontend
-               // TODO: return ((BasketFrontend) this.getFrontend()).getLast();
-               throw new UnsupportedOperationException("Not yet implmeneted.");
+               // Deligate to list
+               return this.deque.getLast();
        }
 
        @Override
        public int getLastNumRows () {
-               // Deligate to frontend
-               // TODO: return this.getFrontend().getLastNumRows();
-               throw new UnsupportedOperationException("Not yet implmeneted.");
+               // Is the list empty?
+               assert this.isEmpty() : "deque is empty"; //NOI18N
+
+               // It is size-1
+               return (this.deque.size() - 1);
        }
 
        @Override
@@ -95,11 +113,7 @@ public abstract class BaseBasket<T extends AddableBasketItem> implements Basket<
                        throw new NullPointerException("item is null"); //NOI18N
                }
 
-               // Call map's method
-               // TODO: boolean isAdded = ((BasketFrontend) this.getFrontend()).isAdded(item, this.getSessionId());
-               boolean isAdded = true;
-
                // Return it
-               return isAdded;
+               return this.deque.contains(item);
        }
 }
index 72d9e07fb5d1f519a8c7d330abb99856a00b8d06..51f4a58906952166510e7e8347f4ddd29debf38e 100644 (file)
@@ -18,20 +18,23 @@ package org.mxchange.jshopcore.model.basket;
 
 import java.io.Serializable;
 import java.util.Map;
+import org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException;
 
 /**
  * An interface for baskets
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  * @param <T> Any addable basket items
  */
 public interface Basket<T extends AddableBasketItem> extends Serializable {
 
        /**
         * Adds given item instance to this basket
+        * 
         * @param item Item instance to add
+        * @throws org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException If the item instance has already been added
         */
-       public void addItem (final T item);
+       public void addItem (final T item) throws BasketItemAlreadyAddedException;
 
        /**
         * Checks whether the given item as already been added. If the product's
@@ -49,11 +52,6 @@ public interface Basket<T extends AddableBasketItem> extends Serializable {
         */
        public boolean isEmpty ();
 
-       /**
-        * Initializes this instance with given ServletContext
-        */
-       public void init ();
-
        /**
         * Some "getter" for all entries in this basket
         *
index fa5213b46d13ad0b6c7a8c0de88a432b16f70961..c24221b063363e9bfe33474f794c9038cdbff5d7 100644 (file)
  */
 package org.mxchange.jshopcore.model.basket;
 
-import java.sql.SQLException;
-
 /**
  * A basket for orderable items
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public class ShopBasket extends BaseBasket<AddableBasketItem> implements Basket<AddableBasketItem> {
        /**
@@ -31,9 +29,8 @@ public class ShopBasket extends BaseBasket<AddableBasketItem> implements Basket<
 
        /**
         * Default constructor to be able to throw exceptions from super constructor
-        * @throws java.sql.SQLException If an SQL error occurs
         */
-       public ShopBasket () throws SQLException {
+       public ShopBasket () {
                // Call super constructor
                super();
        }
index fe5f491d9558ca5753b9f60e5c4fc04ec29a37b8..b83b6bb0435194509bc0fe373cd9fe396cffd897 100644 (file)
@@ -21,7 +21,7 @@ import java.util.Objects;
 /**
  * A general product category class
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public abstract class BaseCategory implements Category, Comparable<Category> {
        /**
index d0432fdc88f50b689331764f9971a0b4f2e2a9d0..a1c49626e8989e3619e532e4ba63a960b6278f4a 100644 (file)
@@ -21,7 +21,7 @@ import java.io.Serializable;
 /**
  * An interface for categories
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public interface Category extends Serializable {
 
index 9bd2a612ee1f396184f056497edf8142f5d776fc..d89077f6711436beb9a50cd74305a7eda95fc997 100644 (file)
@@ -18,7 +18,7 @@ package org.mxchange.jshopcore.model.category;
 
 /**
  * A product category
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public class ProductCategory extends BaseCategory {
        /**
index 4524d65a53da3b3184177f6487628825fd0cd619..21cf303e401fe4c78957060e3f29abbfd1efe19a 100644 (file)
@@ -21,7 +21,7 @@ import org.mxchange.jcore.model.contact.Contact;
 /**
  * A customer interface
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public interface Customer extends Contact {
 }
index 209dd7149fb3b14673e51d607b2b85d8c5f729cc..3e0e0cf5099abc92f52d01f7c039ad4b2c70a172 100644 (file)
@@ -21,7 +21,7 @@ import org.mxchange.jcore.model.contact.BaseContact;
 /**
  * A shop customer class.
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public class ShopCustomer extends BaseContact implements Customer {
        /**
index b7882384c48a506bf996e4c8c76faa21a3a64259..7a8d50c756699c8e4bc91a5e69988c107516ed6a 100644 (file)
@@ -24,7 +24,7 @@ import org.mxchange.jshopcore.model.product.Product;
  * An item (addedable to a basket) could respresent a product or a discount
  * coupon. This depends on the type of the item.
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public abstract class BaseItem implements AddableBasketItem, Comparable<AddableBasketItem> {
 
index a56ccc200359c240e34156264066be8ff5b7e09a..0e19354ac49c9ad70dd07b6a39031ebbe9405e33 100644 (file)
@@ -22,7 +22,7 @@ import org.mxchange.jshopcore.model.product.Product;
 /**
  * A general basket item
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public class BasketItem extends BaseItem implements AddableBasketItem {
        /**
index a2fb9b20c5a8808356c2e2a65c68bb6530922daa..1120636d7952848ff8d3aeb3c7bbdf70b4bbd74f 100644 (file)
@@ -10,7 +10,7 @@ import java.util.Objects;
 /**
  * A general product class
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public abstract class BaseProduct implements Product, Comparable<Product> {
 
index ecd215a1e32b5ef359f9d49ee220e2de78eafaca..a7e8f88a1c99444edcaf3405cfa57508fe65be0d 100644 (file)
@@ -19,7 +19,7 @@ package org.mxchange.jshopcore.model.product;
 /**
  * Generic product class
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  * TODO: Find a better name
  */
 public class GenericProduct extends BaseProduct implements Product {
index efcdd7bc4e80d53e1bf0e70cac845d1339c07cd3..79b94f98dfe4c7c3a12c6f1509434fd0ce2d4a10 100644 (file)
@@ -21,7 +21,7 @@ import java.io.Serializable;
 /**
  * An interface for in database storable products
  *
- * @author Roland Haeder
+ * @author Roland Haeder<roland@mxchange.org>
  */
 public interface Product extends Serializable {
        /**