*/
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;
/**
* 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
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
*
* 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
}
// 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);
// 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
*/
package org.mxchange.pizzaapplication.product;
-import java.text.MessageFormat;
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
*/
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);
- }
}
* @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 ();
}
</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>