]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Got rid of product iterator stuff and used a smaller for() loop
authorRoland Haeder <roland@mxchange.org>
Tue, 11 Aug 2015 09:07:59 +0000 (11:07 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 11 Aug 2015 09:14:17 +0000 (11:14 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java
src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java
src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java
src/java/org/mxchange/pizzaapplication/product/Product.java
web/finished.jsp

index 8d16f755bd0214d7a430f678c09754e74372f165..4f3ca4af20dbd805f711eafe938201675adaf6ed 100644 (file)
@@ -16,8 +16,6 @@
  */
 package org.mxchange.pizzaapplication.application;
 
-import java.util.Iterator;
-import java.util.Map;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import org.mxchange.jcore.application.Application;
@@ -31,29 +29,22 @@ public interface PizzaApplication extends Application {
        /**
         * HTTP parameter "amount"
         */
-       public static final String HTTP_PARAM_AMOUNT = "amount";
+       public static final String HTTP_PARAM_AMOUNT = "amount"; //NOI18N
 
        /**
         * HTTP parameter "choose"
         */
-       public static final String HTTP_PARAM_CHOOSE = "choose";
+       public static final String HTTP_PARAM_CHOOSE = "choose"; //NOI18N
 
        /**
         * Session key "ordered"
         */
-       public static final String SESSION_ORDERED = "ordered";
+       public static final String SESSION_ORDERED = "ordered"; //NOI18N
 
        /**
         * Mask for all parameters
         */
-       public static final String HTTP_PARAM_MASK = "%s[%s]";
-
-       /**
-        * Getter for product iterator
-        * 
-        * @return Iterator for all products
-        */
-       public Iterator<Map.Entry<String, Product>> getProductsIterator ();
+       public static final String HTTP_PARAM_MASK = "%s[%s]"; //NOI18N
 
        /**
         * Some "getter" for amount from session
index 2da95069f36cd4c2d6b17641cecbe2ca8428c492..5a834938e5b52b40a8d8a52d289f2619f2bc343e 100644 (file)
@@ -120,17 +120,6 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
 
-       /**
-        * Getter for product (list) iterator
-        *
-        * @return An interator on all listed products
-        */
-       @Override
-       public Iterator<Map.Entry<String, Product>> getProductsIterator () {
-               assert(this.products instanceof SortedMap) : "this.products is not initialized"; //NOI18N
-               return this.products.entrySet().iterator();
-       }
-
        /**
         * Adds given product to list or throws an exception if name is already found
         *
@@ -337,17 +326,8 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
         * Application starter
         */
        private void start () {
-               // Get iterator
-               Iterator<Map.Entry<String, Product>> iterator = this.getProductsIterator();
-
-               // Run over it
-               while (iterator.hasNext()) {
-                       // Get product instance
-                       Map.Entry<String, Product> entry = iterator.next();
-
-                       // Get value
-                       Product product = entry.getValue();
-
+               // "Walk" over all products
+               for (final Product product : this.getProducts()) {
                        // Output data
                        this.getLogger().debug(MessageFormat.format("Product {0}, {1}: {2}", product.getName(), product.getTitle(), product.getPrice())); //NOI18N
                }
@@ -787,19 +767,10 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                // Init total price
                float totalPrice = 0.00f;
 
-               // Get iterator
-               Iterator<Map.Entry<String, Product>> iterator = this.getProductsIterator();
-
-               // Walk through all products
-               while (iterator.hasNext()) {
-                       // Get entry
-                       Map.Entry<String, Product> entry = iterator.next();
-
-                       // Get product instance
-                       Product product = entry.getValue();
-
+               // "Walk" over all products
+               for (final Product product : this.getProducts()) {
                        // Is this choosen?
-                       if (product.isChoosen()) {
+                       if (this.isProductChoosen(product, request, session)) {
                                // Then add product's total price
                                this.getLogger().debug(MessageFormat.format("Calling getTotalPositionPriceFromRequestSession({0},request,session) ...", product.getName())); //NOI18N
                                totalPrice += this.getTotalPositionPriceFromRequestSession(product, request, session);
@@ -838,19 +809,10 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P
                // Init total price
                int totalAmount = 0;
 
-               // Get iterator
-               Iterator<Map.Entry<String, Product>> iterator = this.getProductsIterator();
-
-               // Walk through all products
-               while (iterator.hasNext()) {
-                       // Get entry
-                       Map.Entry<String, Product> entry = iterator.next();
-
-                       // Get product instance
-                       Product product = entry.getValue();
-
+               // "Walk" over all products
+               for (final Product product : this.getProducts()) {
                        // Is this choosen?
-                       if (product.isChoosen()) {
+                       if (this.isProductChoosen(product, request, session)) {
                                // Then add ordered amount
                                this.getLogger().debug(MessageFormat.format("Counting {0} ...", product.getName())); //NOI18N
 
index ba32ecb5d75b83cc1a77b0d596b42be65ac12263..1f626b97b49fb7276f642acd851c795244807333 100644 (file)
@@ -16,7 +16,6 @@
  */
 package org.mxchange.pizzaapplication.product;
 
-import java.text.MessageFormat;
 import org.mxchange.jcore.BaseFrameworkSystem;
 
 /**
@@ -24,11 +23,6 @@ import org.mxchange.jcore.BaseFrameworkSystem;
  * @author Roland Haeder
  */
 public class PizzaProduct extends BaseFrameworkSystem implements Product {
-       /**
-        * Whether this product is choosen (default: false)
-        */
-       private boolean choosen = false;
-
        /**
         * Name of product
         */
@@ -107,32 +101,4 @@ public class PizzaProduct extends BaseFrameworkSystem implements Product {
        protected final void setTitle (final String title) {
                this.title = title;
        }
-
-       /**
-        * Whether this product is choosen (default: false)
-        *
-        * @return the choosen
-        */
-       @Override
-       public final boolean isChoosen () {
-               return this.choosen;
-       }
-
-       /**
-        * Whether this product is choosen (default: false)
-        * @param choosen the choosen to set
-        */
-       protected final void setChoosen (boolean choosen) {
-               this.choosen = choosen;
-       }
-
-       /**
-        * Marks product as choosen
-        */
-       @Override
-       public void markAsChoosen () {
-               // Set it
-               this.getLogger().debug(MessageFormat.format("product={0} marked as choosen.", this.getName()));
-               this.setChoosen(true);
-       }
 }
index dfe5a70ae9372a575ff93b733cbc840396348e06..a81b91632e057297e1e275cd577c1584f3160173 100644 (file)
@@ -43,16 +43,4 @@ public interface Product extends FrameworkInterface {
         * @return Single price of product
         */
        public float getPrice ();
-
-       /**
-        * Whether this product is choosen (default: false)
-        *
-        * @return the choosen
-        */
-       public boolean isChoosen ();
-
-       /**
-        * Marks product as choosen
-        */
-       public void markAsChoosen ();
 }
index f8054014ac7a9023b5601b5c324cc258d45b46d9..13195b2afb9b47c47cc8f50d1d9e85263f8444cf 100644 (file)
                                        </thead>
                                        <tbody class="table_body">
                                                <%
-                                               // Get iterator from products
-                                               Iterator<Map.Entry<String, Product>> iterator = app.getProductsIterator();
-
-                                               // Iterate over all
-                                               while (iterator.hasNext()) {
-                                                       // Get entry
-                                                       Map.Entry<String, Product> entry = iterator.next();
-
-                                                       // Get product
-                                                       Product product = entry.getValue();
-
-                                                       // Mark product as ordered
-                                                       app.markProductAsOrdered(product, session);
+                                               // "Walk" over all products
+                                               for (final Product product : app.getProducts()) {
+                                                       // Is it choosen?
+                                                       if (app.isProductChoosen(product, request, session)) {
+                                                               // Mark product as ordered
+                                                               app.markProductAsOrdered(product, session);
+                                                       }
                                                        %>
                                                        <tr>
                                                                <td>