From 06f41f1947641dbb49cf6103e8bd1b7346031522 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 11 Aug 2015 11:07:59 +0200 Subject: [PATCH] =?utf8?q?Got=20rid=20of=20product=20iterator=20stuff=20an?= =?utf8?q?d=20used=20a=20smaller=20for()=20loop=20Signed-off-by:Roland=20H?= =?utf8?q?=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../application/PizzaApplication.java | 17 ++---- .../application/PizzaServiceApplication.java | 54 +++---------------- .../product/PizzaProduct.java | 34 ------------ .../pizzaapplication/product/Product.java | 12 ----- web/finished.jsp | 20 +++---- 5 files changed, 19 insertions(+), 118 deletions(-) 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); + } %> -- 2.39.5