Commit e3fd38fc authored by Bhargava Rellu's avatar Bhargava Rellu

java documentation

parent f4d01e03
...@@ -3,7 +3,7 @@ package com.retail_store.order_management.constants; ...@@ -3,7 +3,7 @@ package com.retail_store.order_management.constants;
/** /**
* Here using Enum class types as the requirement has constants to * Here using Enum class types as the requirement has constants to
* use multiple times in the project. * use multiple times in the project.
* * <p>
* So this enumeration class of category shows all options * So this enumeration class of category shows all options
* according to requirement * according to requirement
*/ */
...@@ -15,10 +15,21 @@ public enum Category { ...@@ -15,10 +15,21 @@ public enum Category {
int option; int option;
/**
* Method is used to return option value
* of specific Category enum
*
* @return int
*/
public int getOption() { public int getOption() {
return option; return option;
} }
/**
* Parameterised Constructor
*
* @param option
*/
Category(int option) { Category(int option) {
this.option = option; this.option = option;
} }
......
package com.retail_store.order_management.constants; package com.retail_store.order_management.constants;
/** /**
* Enumeration class of name Color * Enumeration class of name Color
* Used different constants according to the project requirement * Used different constants according to the project requirement
* * <p>
* According to the given option in the console this class methods or functionality * According to the given option in the console this class methods or functionality
* is called * is called
*/ */
...@@ -14,10 +15,21 @@ public enum Color { ...@@ -14,10 +15,21 @@ public enum Color {
EXIT(0), RED(1), GREEN(2), BLUE(3), BROWN(4), GREY(5), WHITE(6), PINK(7), YELLOW(8), BLACK(9), PURPLE(10), ORANGE(11), SKY_BLUE(12); EXIT(0), RED(1), GREEN(2), BLUE(3), BROWN(4), GREY(5), WHITE(6), PINK(7), YELLOW(8), BLACK(9), PURPLE(10), ORANGE(11), SKY_BLUE(12);
int option; int option;
/**
* Method is used to return option value
* of specific Color enum
*
* @return int
*/
public int getOption() { public int getOption() {
return option; return option;
} }
/**
* Parameterised Constructor
*
* @param option
*/
Color(int option) { Color(int option) {
this.option = option; this.option = option;
} }
......
...@@ -2,7 +2,6 @@ package com.retail_store.order_management.constants; ...@@ -2,7 +2,6 @@ package com.retail_store.order_management.constants;
/** /**
* Enumeration class of name Gender * Enumeration class of name Gender
*
* According to the selected option this class behaviour is called to select * According to the selected option this class behaviour is called to select
* particular gender * particular gender
*/ */
...@@ -10,18 +9,36 @@ public enum Gender { ...@@ -10,18 +9,36 @@ public enum Gender {
/** /**
* Different types of Gender enum * Different types of Gender enum
*/ */
EXIT(0,"exit"),MEN(1, "Men"), WOMEN(2, "Women"); EXIT(0, "exit"), MEN(1, "Men"), WOMEN(2, "Women");
int option; int option;
String gender; String gender;
/**
* Method is used to return option value
* of specific Gender enum
*
* @return int
*/
public int getOption() { public int getOption() {
return option; return option;
} }
/**
* Method is used to return the String data
* of specific Gender enum
*
* @return
*/
public String getGender() { public String getGender() {
return gender; return gender;
} }
/**
* Parameterised Constructor
*
* @param option
* @param gender
*/
Gender(int option, String gender) { Gender(int option, String gender) {
this.option = option; this.option = option;
this.gender = gender; this.gender = gender;
......
package com.retail_store.order_management.constants; package com.retail_store.order_management.constants;
/**
* Enumeration class name Size
* Here in this the product constant types are taken as per requirement.
*/
public enum Size { public enum Size {
EXIT(0, "exit"), S(1, "size_s"), M(2, "size_m"), L(3, "size_l"), XL(4, "size_xl"), XXL(5, "size_xxl"); EXIT(0, "exit"), S(1, "size_s"), M(2, "size_m"), L(3, "size_l"), XL(4, "size_xl"), XXL(5, "size_xxl");
int option; int option;
String name; String name;
/**
* Method is used to return option value
* of specific Size enum
*
* @return int
*/
public int getOption() { public int getOption() {
return option; return option;
} }
/**
* Method is used to return the String data
* of specific Size enum
*
* @return
*/
public String getName() { public String getName() {
return name; return name;
} }
/**
* Parameterised Constructor
*
* @param option
* @param name
*/
Size(int option, String name) { Size(int option, String name) {
this.option = option; this.option = option;
this.name = name; this.name = name;
......
package com.retail_store.order_management.model; package com.retail_store.order_management.model;
import lombok.AccessLevel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
...@@ -8,6 +7,10 @@ import java.time.LocalDate; ...@@ -8,6 +7,10 @@ import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.List; import java.util.List;
/**
* This is order class with some states and behaviour
* With all instance variables as private
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class Order { public class Order {
...@@ -19,10 +22,20 @@ public class Order { ...@@ -19,10 +22,20 @@ public class Order {
private double totalBill; private double totalBill;
List<OrderedProduct> productsList; List<OrderedProduct> productsList;
/**
* This method is used to get the order details in brief
*
* @return string
*/
public String showOrder() { public String showOrder() {
return "order id : " + orderId + "\nCustomer name: " + customerName + "\tPhone number: " + phoneNumber + "\nDate: " + orderDate + "\tTime: " + localTime + "\n Total Bill: " + totalBill; return "order id : " + orderId + "\nCustomer name: " + customerName + "\tPhone number: " + phoneNumber + "\nDate: " + orderDate + "\tTime: " + localTime + "\n Total Bill: " + totalBill;
} }
/**
* This method is used to get the all products list present.
*
* @return string
*/
public String showProducts() { public String showProducts() {
return productsList.stream().map(product -> product.getId() + "\t" + product.getName() + "\n" + product.getCategory() + "\t" + product.getSize() + "\n" + product.getQuantity() + "\t" + product.getPrice() + "\t" + product.getQuantity() * product.getPrice()).reduce("", (productsList, product) -> productsList + "\n" + product); return productsList.stream().map(product -> product.getId() + "\t" + product.getName() + "\n" + product.getCategory() + "\t" + product.getSize() + "\n" + product.getQuantity() + "\t" + product.getPrice() + "\t" + product.getQuantity() * product.getPrice()).reduce("", (productsList, product) -> productsList + "\n" + product);
} }
......
...@@ -5,10 +5,14 @@ import com.retail_store.order_management.constants.Category; ...@@ -5,10 +5,14 @@ import com.retail_store.order_management.constants.Category;
import com.retail_store.order_management.constants.Color; import com.retail_store.order_management.constants.Color;
import com.retail_store.order_management.constants.Gender; import com.retail_store.order_management.constants.Gender;
import com.retail_store.order_management.constants.Size; import com.retail_store.order_management.constants.Size;
import lombok.AccessLevel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
/**
* Class OrderedProduct is used get all the ordered products in specific manner
* which are chosen by the end user
* by with respective variables and methods
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class OrderedProduct { public class OrderedProduct {
...@@ -21,6 +25,11 @@ public class OrderedProduct { ...@@ -21,6 +25,11 @@ public class OrderedProduct {
private Size size; private Size size;
private int quantity; private int quantity;
/**
* This method returns the content of the OrderedProducts in String format
*
* @return string
*/
@Override @Override
public String toString() { public String toString() {
return "OrderedProduct{" + return "OrderedProduct{" +
......
...@@ -5,12 +5,16 @@ import com.retail_store.order_management.constants.Category; ...@@ -5,12 +5,16 @@ import com.retail_store.order_management.constants.Category;
import com.retail_store.order_management.constants.Color; import com.retail_store.order_management.constants.Color;
import com.retail_store.order_management.constants.Gender; import com.retail_store.order_management.constants.Gender;
import com.retail_store.order_management.constants.Size; import com.retail_store.order_management.constants.Size;
import lombok.AccessLevel;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import java.util.Map; import java.util.Map;
/**
* CLass product
* ...In this all the variables and methods are
* used to create the product list as required per the admin
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class Product { public class Product {
...@@ -22,22 +26,51 @@ public class Product { ...@@ -22,22 +26,51 @@ public class Product {
private Gender idealFor; private Gender idealFor;
private Map<Size, Integer> size; private Map<Size, Integer> size;
/**
* This method is used to get all the available sizes in the product list
* of in the string format
*
* @return
*/
public String getProductSizeAvailability() { public String getProductSizeAvailability() {
return size.entrySet().stream().map(entry -> entry.getKey() + " - " + entry.getValue()).reduce("", (sizes, size) -> sizes + "\n" + size.toString()); return size.entrySet().stream().map(entry -> entry.getKey() + " - " + entry.getValue()).reduce("", (sizes, size) -> sizes + "\n" + size.toString());
} }
/**
* This method is used to get the boolean value according to
* the availability of the stock in products table
*
* @return boolean -> true,false
*/
public boolean outOfStock() { public boolean outOfStock() {
return size.entrySet().stream().allMatch(entry -> entry.getValue() <= 0); return size.entrySet().stream().allMatch(entry -> entry.getValue() <= 0);
} }
/**
* This method is used to get the whether the sizes are out of stock or
* present in the database if present the sizes are shown
*
* @return string
*/
public String showSizes() { public String showSizes() {
return outOfStock() ? "* Out of Stock *" : "Sizes available : " + size.entrySet().stream().map(size -> size.getKey() + "-" + size.getValue()).reduce((sizes, size) -> sizes + ", " + size).get(); return outOfStock() ? "* Out of Stock *" : "Sizes available : " + size.entrySet().stream().map(size -> size.getKey() + "-" + size.getValue()).reduce((sizes, size) -> sizes + ", " + size).get();
} }
/**
* This method is used to get the menu of the product according to the required
* variables which are used above
*
* @return string
*/
public String productShowcaseInMenu() { public String productShowcaseInMenu() {
return getName() + "\t" + getPrice() + "\n " + getColor() + "\t" + showSizes(); return getName() + "\t" + getPrice() + "\n " + getColor() + "\t" + showSizes();
} }
/**
* This is method to give the product values in string format
*
* @return string
*/
@Override @Override
public String toString() { public String toString() {
return "Product{" + return "Product{" +
......
...@@ -9,15 +9,47 @@ import com.retail_store.order_management.model.Product; ...@@ -9,15 +9,47 @@ import com.retail_store.order_management.model.Product;
import java.sql.Connection; import java.sql.Connection;
import java.util.Map; import java.util.Map;
/**
* interface ProductFilter
* This is an interface to filter the products according to
* respective of taken methods in this interface
*/
public interface ProductFilter { public interface ProductFilter {
/**
* This is an abstract method gives the
* categories of product according selection of gender type
*
* @param gender
* @return category according key value of type integer
*/
public Map<Integer, Category> getCategoriesByGender(Gender gender); public Map<Integer, Category> getCategoriesByGender(Gender gender);
/**
* This abstract method is used to get the all orders present
*
* @param connection
* @return order according to key value of type integer
*/
public Map<Integer, Order> getOrders(Connection connection); public Map<Integer, Order> getOrders(Connection connection);
/**
* This abstract method is used to get the colors present to the products which
* are filter according to the Gender and Category
*
* @param gender
* @param category
* @return color according to key value of type integer
*/
public Map<Integer, Color> getColorsByGenderAndCategory(Gender gender, Category category); public Map<Integer, Color> getColorsByGenderAndCategory(Gender gender, Category category);
/**
* This abstract method gives all the products which are
* filtered by the gender and category
*
* @param gender
* @param category
* @return product according to key value of type integer
*/
public Map<Integer, Product> getProductsByGenderAndCategory(Gender gender, Category category); public Map<Integer, Product> getProductsByGenderAndCategory(Gender gender, Category category);
} }
...@@ -7,14 +7,47 @@ import com.retail_store.order_management.model.Product; ...@@ -7,14 +7,47 @@ import com.retail_store.order_management.model.Product;
import java.sql.Connection; import java.sql.Connection;
import java.util.Collection; import java.util.Collection;
/**
* Interface RetailStore
* In this interface there present different abstract methods to perform
* various functions of the project
*/
public interface RetailStore { public interface RetailStore {
/**
* This abstract method is used to add the products seemly according to the
* given process in the console, if added then shows message accordingly
*
* @return boolean -> true/false
*/
public boolean addProducts(); public boolean addProducts();
/**
* This abstract method is used to place the orders of the available products
*
* @return boolean -> true/false
*/
public boolean placeOrders(); public boolean placeOrders();
/**
* This abstract method is used to show what all orders are generated
*/
public void showOrders(); public void showOrders();
/**
* This abstract method is used to generate order list of the products those placed
*
* @param connection
* @return OrderedProduct
*/
public Collection<OrderedProduct> createOrder(Connection connection); public Collection<OrderedProduct> createOrder(Connection connection);
/**
* This abstract method is used to push all the chosen products to the cart
*
* @param cart
* @param product
* @param connection
* @return boolean -> true/false
*/
public boolean addProductToCart(Collection<OrderedProduct> cart, Product product, Connection connection); public boolean addProductToCart(Collection<OrderedProduct> cart, Product product, Connection connection);
} }
...@@ -18,7 +18,11 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -18,7 +18,11 @@ import java.util.concurrent.atomic.AtomicInteger;
import static com.retail_store.order_management.utils.Database.getConnection; import static com.retail_store.order_management.utils.Database.getConnection;
import static com.retail_store.order_management.utils.Utility.*; import static com.retail_store.order_management.utils.Utility.*;
/**
* Class RetailStoreService
* This class implements from previous interfaces RetailStore and ProductFilter so
* that all the unimplemented methods should be implemented here and given there logic inside
*/
public class RetailStoreService implements RetailStore, ProductFilter { public class RetailStoreService implements RetailStore, ProductFilter {
public boolean addProducts() { public boolean addProducts() {
......
...@@ -4,12 +4,26 @@ import java.sql.Connection; ...@@ -4,12 +4,26 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
/**
* Class Database
* This is a final class in which all the configurations of the database are present to
* establish the connection to the database to the project
*/
public final class Database { public final class Database {
private static Connection connection; private static Connection connection;
/**
* Private constructor that will not
* allow to create object
*/
private Database() { private Database() {
} }
/**
* This is used to establish the connection to the database
*
* @return connection
*/
public static Connection getConnection() { public static Connection getConnection() {
String url = "jdbc:mysql://localhost:3306/gap"; String url = "jdbc:mysql://localhost:3306/gap";
String userName = "root"; String userName = "root";
......
...@@ -11,13 +11,29 @@ import com.retail_store.order_management.service.RetailStore; ...@@ -11,13 +11,29 @@ import com.retail_store.order_management.service.RetailStore;
import java.util.*; import java.util.*;
import java.util.logging.Logger; import java.util.logging.Logger;
/**
* Class Utility
* This is class is used to finalize the all the methods present and those are static
* Class used to import the values of the option given in the console and print accordingly
* of the required choice chosen
*/
public final class Utility { public final class Utility {
private static final Scanner SCANNER = null; private static final Scanner SCANNER = null;
private static final Logger LOGGER = null; private static final Logger LOGGER = null;
/**
* No argument constructor
*/
private Utility() { private Utility() {
} }
/**
* This static method is used to get the category list according to check with given inout message
*
* @param check
* @param message
* @return category
*/
public static Category getCategory(boolean check, String message) { public static Category getCategory(boolean check, String message) {
Category categoryValue; Category categoryValue;
String categoryOptions = Arrays.stream(Category.values()).filter(category -> !category.equals(Category.EXIT)).map(category -> "(" + category.getOption() + ")" + category).reduce((categories, category) -> categories + " " + category).get() + "\nPress 0 to go back."; String categoryOptions = Arrays.stream(Category.values()).filter(category -> !category.equals(Category.EXIT)).map(category -> "(" + category.getOption() + ")" + category).reduce((categories, category) -> categories + " " + category).get() + "\nPress 0 to go back.";
...@@ -32,6 +48,13 @@ public final class Utility { ...@@ -32,6 +48,13 @@ public final class Utility {
return categoryValue.equals(Category.EXIT) ? null : categoryValue; return categoryValue.equals(Category.EXIT) ? null : categoryValue;
} }
/**
* This static method is used to get the Sizes of the given input option of the message
*
* @param check
* @param message
* @return
*/
public static Size getSize(boolean check, String message) { public static Size getSize(boolean check, String message) {
Size sizeValue; 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.";
...@@ -46,6 +69,13 @@ public final class Utility { ...@@ -46,6 +69,13 @@ public final class Utility {
return sizeValue.equals(Size.EXIT) ? null : sizeValue; return sizeValue.equals(Size.EXIT) ? null : sizeValue;
} }
/**
* This method is used to get the gender details of the given input option
*
* @param check
* @param message
* @return gender
*/
public static Gender getGender(boolean check, String message) { public static Gender getGender(boolean check, String message) {
Gender genderValue; Gender genderValue;
String genderOptions = Arrays.stream(Gender.values()).filter(gender -> !gender.equals(Gender.EXIT)).map(gender -> "(" + gender.getOption() + ")" + gender).reduce((genders, gender) -> genders + " " + gender).get() + "\nPress 0 to go back."; String genderOptions = Arrays.stream(Gender.values()).filter(gender -> !gender.equals(Gender.EXIT)).map(gender -> "(" + gender.getOption() + ")" + gender).reduce((genders, gender) -> genders + " " + gender).get() + "\nPress 0 to go back.";
...@@ -60,6 +90,13 @@ public final class Utility { ...@@ -60,6 +90,13 @@ public final class Utility {
return genderValue.equals(Gender.EXIT) ? null : genderValue; return genderValue.equals(Gender.EXIT) ? null : genderValue;
} }
/**
* This method is used to get all the colors of the given input option
*
* @param check
* @param message
* @return color
*/
public static Color getColor(boolean check, String message) { public static Color getColor(boolean check, String message) {
Color colorValue; Color colorValue;
String colorOptions = Arrays.stream(Color.values()).filter(color -> !color.equals(Color.EXIT)).map(color -> "(" + color.getOption() + ")" + color).reduce((categories, category) -> categories + " " + category).get() + "\nPress 0 to go back."; String colorOptions = Arrays.stream(Color.values()).filter(color -> !color.equals(Color.EXIT)).map(color -> "(" + color.getOption() + ")" + color).reduce((categories, category) -> categories + " " + category).get() + "\nPress 0 to go back.";
...@@ -74,6 +111,14 @@ public final class Utility { ...@@ -74,6 +111,14 @@ public final class Utility {
return colorValue.equals(Color.EXIT) ? null : colorValue; return colorValue.equals(Color.EXIT) ? null : colorValue;
} }
/**
* This method is used to get the message as per invalid option if
* you enter other options or other input than shown there.
*
* @param flag
* @param message
* @return double
*/
public static double getDouble(boolean flag, String message) { public static double getDouble(boolean flag, String message) {
double number; double number;
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
...@@ -93,6 +138,12 @@ public final class Utility { ...@@ -93,6 +138,12 @@ public final class Utility {
} }
} }
/**
* This method is used to get the message as per invalid option if
* you enter other options or other input than shown there.
*
* @return int
*/
public static int getInt() { public static int getInt() {
int number; int number;
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
...@@ -109,6 +160,13 @@ public final class Utility { ...@@ -109,6 +160,13 @@ public final class Utility {
} }
} }
/**
* This method is used to take phone number input
* and validate it without any non numeric values and
* numbers must be 10 and returns String phone number
*
* @return
*/
public static String phoneNumberValidator() { public static String phoneNumberValidator() {
String phoneNumber; String phoneNumber;
try { try {
...@@ -123,14 +181,31 @@ public final class Utility { ...@@ -123,14 +181,31 @@ public final class Utility {
return phoneNumber.toString(); return phoneNumber.toString();
} }
/**
* This method is used to create a singleton
* logger object that is used throughout the application
*
* @return
*/
public static Logger getLogger() { public static Logger getLogger() {
return LOGGER == null ? Logger.getLogger(OrderManagement.class.getName()) : LOGGER; return LOGGER == null ? Logger.getLogger(OrderManagement.class.getName()) : LOGGER;
} }
/**
* This method is used to create a singleton
* scanner object that is used throughout the application
*
* @return
*/
public static Scanner getScanner() { public static Scanner getScanner() {
return SCANNER == null ? new Scanner(System.in) : SCANNER; return SCANNER == null ? new Scanner(System.in) : SCANNER;
} }
/**
* This method is used to give a valid number that present in the stock range
*
* @return integer according to key type size
*/
public static LinkedHashMap<Size, Integer> getProductSizes() { public static LinkedHashMap<Size, Integer> getProductSizes() {
LinkedHashMap<Size, Integer> productSizes = new LinkedHashMap<>(); LinkedHashMap<Size, Integer> productSizes = new LinkedHashMap<>();
getLogger().info("Please enter the available stock for particular sizes \n Number of products with size S"); getLogger().info("Please enter the available stock for particular sizes \n Number of products with size S");
...@@ -146,6 +221,17 @@ public final class Utility { ...@@ -146,6 +221,17 @@ public final class Utility {
return productSizes; return productSizes;
} }
/**
* This method is used to give the product sizes available in the database according to
* the key value pair inserted in the database
*
* @param s
* @param m
* @param l
* @param xl
* @param xxl
* @return integer according to key type size
*/
public static Map<Size, Integer> getProductSizes(int s, int m, int l, int xl, int xxl) { public static Map<Size, Integer> getProductSizes(int s, int m, int l, int xl, int xxl) {
LinkedHashMap<Size, Integer> productSizes = new LinkedHashMap<>(); LinkedHashMap<Size, Integer> productSizes = new LinkedHashMap<>();
productSizes.put(Size.S, s); productSizes.put(Size.S, s);
...@@ -156,10 +242,22 @@ public final class Utility { ...@@ -156,10 +242,22 @@ public final class Utility {
return productSizes; return productSizes;
} }
/**
* This method is to generate automatic unique productId for the products
* while adding them.
*
* @return string
*/
public static String productIdGenerator() { public static String productIdGenerator() {
return Arrays.stream(UUID.randomUUID().toString().split("-")).skip(1).findFirst().get() + "#" + RetailStore.class.getSimpleName(); return Arrays.stream(UUID.randomUUID().toString().split("-")).skip(1).findFirst().get() + "#" + RetailStore.class.getSimpleName();
} }
/**
* This method is to generate automatic unique orderId for the orders which are placed
* by the end user.
*
* @return string
*/
public static String orderIdGenerator() { public static String orderIdGenerator() {
return Arrays.stream(UUID.randomUUID().toString().split("-")).findFirst().get() + "#" + Order.class.getSimpleName(); return Arrays.stream(UUID.randomUUID().toString().split("-")).findFirst().get() + "#" + Order.class.getSimpleName();
} }
......
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