java documentation

parent 95c640a8
...@@ -9,17 +9,29 @@ import java.util.logging.Logger; ...@@ -9,17 +9,29 @@ import java.util.logging.Logger;
import static com.retail_store.order_management.utils.Utility.getInt; import static com.retail_store.order_management.utils.Utility.getInt;
/**
* The project run starts from here
*/
public class OrderManagement { public class OrderManagement {
private Scanner scanner; private Scanner scanner;
private final Logger logger; private final Logger logger;
/**
* Parameterised Constructor for class OrderManagement with their private
* instance variables
*/
public OrderManagement() { public OrderManagement() {
System.setProperty("java.util.logging.SimpleFormatter.format", System.setProperty("java.util.logging.SimpleFormatter.format",
"%5$s %n"); "%5$s %n");
this.scanner = new Scanner(System.in); this.scanner = new Scanner(System.in);
this.logger = Logger.getLogger(OrderManagement.class.getName()); this.logger = Logger.getLogger(OrderManagement.class.getName());
} }
/**
* Method menu where it shows there regular options to go particular
* functionality regarding the selected option in the console.
* <p>
* And also in this method if any exceptions raised those are handled
*/
public void menu() { public void menu() {
boolean flag = true; boolean flag = true;
logger.info("Welcome to GAP Business Management"); logger.info("Welcome to GAP Business Management");
...@@ -68,7 +80,11 @@ public class OrderManagement { ...@@ -68,7 +80,11 @@ public class OrderManagement {
} }
} }
} }
/**
* Main method with handling exception if raised
*
* @param args
*/
public static void main(String[] args) throws SQLException { public static void main(String[] args) throws SQLException {
OrderManagement orderManagement = new OrderManagement(); OrderManagement orderManagement = new OrderManagement();
orderManagement.menu(); orderManagement.menu();
......
package com.retail_store.order_management.constants; package com.retail_store.order_management.constants;
/**
* Here using Enum class types as the requirement has constants to
* use multiple times in the project.
*
* So this enumeration class of category shows all options
* according to requirement
*/
public enum Category { public enum Category {
EXIT(0), SHIRTS(1), PANTS(2), JEANS(3), SHORTS(4), T_SHIRTS(5), POLOS(6), HOODIES(7), KURTA(8), SWEATSHIRTS(9), DRESS(10), TOPS(11); EXIT(0), SHIRTS(1), PANTS(2), JEANS(3), SHORTS(4), T_SHIRTS(5), POLOS(6), HOODIES(7), KURTA(8), SWEATSHIRTS(9), DRESS(10), TOPS(11);
int option; int option;
/**
* This method returns the option given in console.
* @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
* Used different constants according to the project requirement
*
* According to the given option in the console this class methods or functionality
* is called
*/
public enum Color { 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 returns according to the selected option in the console
* @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;
} }
......
package com.retail_store.order_management.constants; package com.retail_store.order_management.constants;
/**
* Enumeration class of name Gender
*
* According to the selected option this class behaviour is called to select
* particular gender
*/
public enum Gender { public enum Gender {
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 called as per the selected option
* @return int
*/
public int getOption() { public int getOption() {
return option; return option;
} }
/**
* Method is called and returned which particular gender is selected
* @return String
*/
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;
...@@ -8,11 +12,18 @@ public enum Size { ...@@ -8,11 +12,18 @@ public enum Size {
public int getOption() { public int getOption() {
return option; return option;
} }
/**
* Method used to return the name of the selected option
* @return String
*/
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;
......
...@@ -8,6 +8,10 @@ import java.time.LocalDate; ...@@ -8,6 +8,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 {
...@@ -18,11 +22,17 @@ public class Order { ...@@ -18,11 +22,17 @@ public class Order {
private String phoneNumber; private String phoneNumber;
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);
} }
......
...@@ -9,6 +9,11 @@ import lombok.AccessLevel; ...@@ -9,6 +9,11 @@ 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 +26,10 @@ public class OrderedProduct { ...@@ -21,6 +26,10 @@ 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{" +
......
...@@ -11,6 +11,11 @@ import lombok.Getter; ...@@ -11,6 +11,11 @@ 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 +27,45 @@ public class Product { ...@@ -22,22 +27,45 @@ 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,44 @@ import com.retail_store.order_management.model.Product; ...@@ -9,15 +9,44 @@ 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,43 @@ import com.retail_store.order_management.model.Product; ...@@ -7,14 +7,43 @@ 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,16 +4,28 @@ import java.sql.Connection; ...@@ -4,16 +4,28 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
/**
* Class Database
* In this class 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;
/**
* No argument constructor
*/
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";
String password = "123mysql143"; String password = "root";
if (connection == null) { if (connection == null) {
try { try {
Class.forName("com.mysql.cj.jdbc.Driver"); Class.forName("com.mysql.cj.jdbc.Driver");
......
...@@ -11,13 +11,28 @@ import com.retail_store.order_management.service.RetailStore; ...@@ -11,13 +11,28 @@ 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) {
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.";
if (check) { if (check) {
...@@ -30,6 +45,12 @@ public final class Utility { ...@@ -30,6 +45,12 @@ public final class Utility {
}); });
} }
/**
* 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) {
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) {
...@@ -42,6 +63,12 @@ public final class Utility { ...@@ -42,6 +63,12 @@ public final class Utility {
}); });
} }
/**
* 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) {
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.";
if (check) { if (check) {
...@@ -54,6 +81,12 @@ public final class Utility { ...@@ -54,6 +81,12 @@ public final class Utility {
}); });
} }
/**
* 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) {
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.";
if (check) { if (check) {
...@@ -66,6 +99,13 @@ public final class Utility { ...@@ -66,6 +99,13 @@ 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.
* @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);
...@@ -85,6 +125,11 @@ public final class Utility { ...@@ -85,6 +125,11 @@ 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 +154,10 @@ public final class Utility { ...@@ -109,6 +154,10 @@ public final class Utility {
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");
...@@ -124,6 +173,16 @@ public final class Utility { ...@@ -124,6 +173,16 @@ 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);
...@@ -134,10 +193,20 @@ public final class Utility { ...@@ -134,10 +193,20 @@ 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