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;
/**
* Here using Enum class types as the requirement has constants to
* use multiple times in the project.
*
* <p>
* So this enumeration class of category shows all options
* according to requirement
*/
......@@ -15,10 +15,21 @@ public enum Category {
int option;
/**
* Method is used to return option value
* of specific Category enum
*
* @return int
*/
public int getOption() {
return option;
}
/**
* Parameterised Constructor
*
* @param option
*/
Category(int option) {
this.option = option;
}
......
package com.retail_store.order_management.constants;
/**
* Enumeration class of name Color
* Used different constants according to the project requirement
*
* <p>
* According to the given option in the console this class methods or functionality
* is called
*/
......@@ -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);
int option;
/**
* Method is used to return option value
* of specific Color enum
*
* @return int
*/
public int getOption() {
return option;
}
/**
* Parameterised Constructor
*
* @param option
*/
Color(int option) {
this.option = option;
}
......
......@@ -2,7 +2,6 @@ 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
*/
......@@ -10,18 +9,36 @@ public enum Gender {
/**
* 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;
String gender;
/**
* Method is used to return option value
* of specific Gender enum
*
* @return int
*/
public int getOption() {
return option;
}
/**
* Method is used to return the String data
* of specific Gender enum
*
* @return
*/
public String getGender() {
return gender;
}
/**
* Parameterised Constructor
*
* @param option
* @param gender
*/
Gender(int option, String gender) {
this.option = option;
this.gender = gender;
......
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 {
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;
String name;
/**
* Method is used to return option value
* of specific Size enum
*
* @return int
*/
public int getOption() {
return option;
}
/**
* Method is used to return the String data
* of specific Size enum
*
* @return
*/
public String getName() {
return name;
}
/**
* Parameterised Constructor
*
* @param option
* @param name
*/
Size(int option, String name) {
this.option = option;
this.name = name;
......
package com.retail_store.order_management.model;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
......@@ -8,6 +7,10 @@ import java.time.LocalDate;
import java.time.LocalTime;
import java.util.List;
/**
* This is order class with some states and behaviour
* With all instance variables as private
*/
@Getter
@AllArgsConstructor
public class Order {
......@@ -19,10 +22,20 @@ public class Order {
private double totalBill;
List<OrderedProduct> productsList;
/**
* This method is used to get the order details in brief
*
* @return string
*/
public String showOrder() {
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() {
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;
import com.retail_store.order_management.constants.Color;
import com.retail_store.order_management.constants.Gender;
import com.retail_store.order_management.constants.Size;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
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
@AllArgsConstructor
public class OrderedProduct {
......@@ -21,6 +25,11 @@ public class OrderedProduct {
private Size size;
private int quantity;
/**
* This method returns the content of the OrderedProducts in String format
*
* @return string
*/
@Override
public String toString() {
return "OrderedProduct{" +
......
......@@ -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.Gender;
import com.retail_store.order_management.constants.Size;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
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
@AllArgsConstructor
public class Product {
......@@ -22,22 +26,51 @@ public class Product {
private Gender idealFor;
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() {
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() {
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() {
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() {
return getName() + "\t" + getPrice() + "\n " + getColor() + "\t" + showSizes();
}
/**
* This is method to give the product values in string format
*
* @return string
*/
@Override
public String toString() {
return "Product{" +
......
......@@ -9,15 +9,47 @@ import com.retail_store.order_management.model.Product;
import java.sql.Connection;
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 {
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
}
......@@ -7,14 +7,47 @@ import com.retail_store.order_management.model.Product;
import java.sql.Connection;
import java.util.Collection;
/**
* Interface RetailStore
* In this interface there present different abstract methods to perform
* various functions of the project
*/
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();
/**
* This abstract method is used to place the orders of the available products
*
* @return boolean -> true/false
*/
public boolean placeOrders();
/**
* This abstract method is used to show what all orders are generated
*/
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);
/**
* 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);
}
......@@ -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.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 boolean addProducts() {
......
......@@ -4,12 +4,26 @@ import java.sql.Connection;
import java.sql.DriverManager;
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 {
private static Connection connection;
/**
* Private constructor that will not
* allow to create object
*/
private Database() {
}
/**
* This is used to establish the connection to the database
*
* @return connection
*/
public static Connection getConnection() {
String url = "jdbc:mysql://localhost:3306/gap";
String userName = "root";
......
......@@ -11,13 +11,29 @@ import com.retail_store.order_management.service.RetailStore;
import java.util.*;
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 {
private static final Scanner SCANNER = null;
private static final Logger LOGGER = null;
/**
* No argument constructor
*/
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) {
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.";
......@@ -32,6 +48,13 @@ public final class Utility {
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) {
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.";
......@@ -46,6 +69,13 @@ public final class Utility {
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) {
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.";
......@@ -60,6 +90,13 @@ public final class Utility {
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) {
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.";
......@@ -74,6 +111,14 @@ public final class Utility {
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) {
double number;
Scanner scanner = new Scanner(System.in);
......@@ -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() {
int number;
Scanner scanner = new Scanner(System.in);
......@@ -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() {
String phoneNumber;
try {
......@@ -123,14 +181,31 @@ public final class Utility {
return phoneNumber.toString();
}
/**
* This method is used to create a singleton
* logger object that is used throughout the application
*
* @return
*/
public static Logger getLogger() {
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() {
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() {
LinkedHashMap<Size, Integer> productSizes = new LinkedHashMap<>();
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 {
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) {
LinkedHashMap<Size, Integer> productSizes = new LinkedHashMap<>();
productSizes.put(Size.S, s);
......@@ -156,10 +242,22 @@ public final class Utility {
return productSizes;
}
/**
* This method is to generate automatic unique productId for the products
* while adding them.
*
* @return string
*/
public static String productIdGenerator() {
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() {
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