From: Roland Haeder Date: Tue, 11 Aug 2015 09:07:59 +0000 (+0200) Subject: Got rid of product iterator stuff and used a smaller for() loop X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=06f41f1947641dbb49cf6103e8bd1b7346031522;p=pizzaservice-war.git Got rid of product iterator stuff and used a smaller for() loop Signed-off-by:Roland Häder --- diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java index 8d16f755..4f3ca4af 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaApplication.java @@ -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> getProductsIterator (); + public static final String HTTP_PARAM_MASK = "%s[%s]"; //NOI18N /** * Some "getter" for amount from session diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index 2da95069..5a834938 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -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> 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> iterator = this.getProductsIterator(); - - // Run over it - while (iterator.hasNext()) { - // Get product instance - Map.Entry 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> iterator = this.getProductsIterator(); - - // Walk through all products - while (iterator.hasNext()) { - // Get entry - Map.Entry 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> iterator = this.getProductsIterator(); - - // Walk through all products - while (iterator.hasNext()) { - // Get entry - Map.Entry 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 diff --git a/src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java b/src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java index ba32ecb5..1f626b97 100644 --- a/src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java +++ b/src/java/org/mxchange/pizzaapplication/product/PizzaProduct.java @@ -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); - } } diff --git a/src/java/org/mxchange/pizzaapplication/product/Product.java b/src/java/org/mxchange/pizzaapplication/product/Product.java index dfe5a70a..a81b9163 100644 --- a/src/java/org/mxchange/pizzaapplication/product/Product.java +++ b/src/java/org/mxchange/pizzaapplication/product/Product.java @@ -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 (); } diff --git a/web/finished.jsp b/web/finished.jsp index f8054014..13195b2a 100644 --- a/web/finished.jsp +++ b/web/finished.jsp @@ -65,19 +65,13 @@ <% - // Get iterator from products - Iterator> iterator = app.getProductsIterator(); - - // Iterate over all - while (iterator.hasNext()) { - // Get entry - Map.Entry 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); + } %>