Commit ad58caf7 authored by Ramu Dosapati's avatar Ramu Dosapati

Utility class getSize method updated

parent 0a9eb20d
OrderManagementForRetailStore
\ No newline at end of file
...@@ -213,11 +213,11 @@ public class RetailStoreService implements RetailStore, ProductFilter { ...@@ -213,11 +213,11 @@ public class RetailStoreService implements RetailStore, ProductFilter {
@Override @Override
public synchronized boolean addProductToCart(Collection<OrderedProduct> cart, Product product, Connection connection) { public synchronized boolean addProductToCart(Collection<OrderedProduct> cart, Product product, Connection connection) {
if (product.outOfStock()) {
return false;
}
getLogger().info(product.showSizes()); getLogger().info(product.showSizes());
Size size = getSize(true, "Please Select Size"); Size size = getSize(true, "Please Select Size");
if (product.outOfStock() || size == null) {
return false;
}
getLogger().info("\n-----------------------------\nPlease enter quantity required\n-----------------------------\n"); getLogger().info("\n-----------------------------\nPlease enter quantity required\n-----------------------------\n");
int quantity = getInt(); int quantity = getInt();
int availableQuantity = product.getSize().get(size); int availableQuantity = product.getSize().get(size);
......
...@@ -52,15 +52,18 @@ public final class Utility { ...@@ -52,15 +52,18 @@ public final class Utility {
* @return * @return
*/ */
public static Size getSize(boolean check, String message) { public static Size getSize(boolean check, String message) {
Size sizeValue;
String categoryOptions = Arrays.stream(Size.values()).filter(size -> !size.equals(Size.EXIT)).map(size -> "(" + size.getOption() + ")" + size).reduce((sizes, size) -> sizes + " " + size).get() + "\nPress 0 to go back."; String categoryOptions = Arrays.stream(Size.values()).filter(size -> !size.equals(Size.EXIT)).map(size -> "(" + size.getOption() + ")" + size).reduce((sizes, size) -> sizes + " " + size).get() + "\nPress 0 to go back.";
if (check) { if (check) {
getLogger().info("\n------------------------\n" + message + "\n------------------------\n" + categoryOptions + "\n------------------------\n"); getLogger().info("\n------------------------\n" + message + "\n------------------------\n" + categoryOptions + "\n------------------------\n");
} }
int option = getInt(); int option = getInt();
return Arrays.stream(Size.values()).filter(size -> size.getOption() == option).findFirst().orElseGet(() -> { sizeValue = Arrays.stream(Size.values()).filter(size -> size.getOption() == option).findFirst().orElseGet(() -> {
getLogger().info("\n------------------------\nPlease enter valid category\n------------------------\n" + categoryOptions + "\n------------------------\n"); getLogger().info("\n------------------------\nPlease enter valid category\n------------------------\n" + categoryOptions + "\n------------------------\n");
return getSize(false, message); return getSize(false, message);
}); });
return sizeValue.equals(Size.EXIT) ? null : sizeValue;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment