From 7ba5746ea31d1f0832a2d65e2541643ee6148048 Mon Sep 17 00:00:00 2001 From: LEE SEONGMIN Date: Sun, 21 May 2023 17:46:28 +0900 Subject: [PATCH] =?UTF-8?q?[1=EC=B0=A8=20VER1.0...]=20Java=20ToyProject=20?= =?UTF-8?q?upload=20by=20SeongminLee?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- me/smartstore/Main.java | 7 + me/smartstore/SmartStoreApplication.java | 81 ++++++ .../customers/ClassifiedCustomers.java | 48 +++ .../customers/ClassifiedCustomersGroup.java | 94 ++++++ me/smartstore/customers/Customer.java | 96 ++++++ me/smartstore/customers/Customers.java | 250 ++++++++++++++++ .../exception/ArrayEmptyException.java | 11 + .../exception/InputEmptyException.java | 11 + .../exception/InputEndException.java | 11 + .../exception/InputFormatException.java | 11 + .../exception/InputRangeException.java | 11 + .../exception/InputTypeException.java | 11 + me/smartstore/groups/Group.java | 66 +++++ me/smartstore/groups/GroupType.java | 42 +++ me/smartstore/groups/Groups.java | 108 +++++++ me/smartstore/groups/Parameter.java | 50 ++++ me/smartstore/menu/CustomerMenu.java | 273 ++++++++++++++++++ me/smartstore/menu/GroupMenu.java | 215 ++++++++++++++ me/smartstore/menu/Menu.java | 68 +++++ me/smartstore/menu/OrderType.java | 34 +++ me/smartstore/menu/SummarizedMenu.java | 110 +++++++ me/smartstore/util/Message.java | 13 + me/smartstore/util/UtilMethod.java | 14 + 23 files changed, 1635 insertions(+) create mode 100644 me/smartstore/Main.java create mode 100644 me/smartstore/SmartStoreApplication.java create mode 100644 me/smartstore/customers/ClassifiedCustomers.java create mode 100644 me/smartstore/customers/ClassifiedCustomersGroup.java create mode 100644 me/smartstore/customers/Customer.java create mode 100644 me/smartstore/customers/Customers.java create mode 100644 me/smartstore/exception/ArrayEmptyException.java create mode 100644 me/smartstore/exception/InputEmptyException.java create mode 100644 me/smartstore/exception/InputEndException.java create mode 100644 me/smartstore/exception/InputFormatException.java create mode 100644 me/smartstore/exception/InputRangeException.java create mode 100644 me/smartstore/exception/InputTypeException.java create mode 100644 me/smartstore/groups/Group.java create mode 100644 me/smartstore/groups/GroupType.java create mode 100644 me/smartstore/groups/Groups.java create mode 100644 me/smartstore/groups/Parameter.java create mode 100644 me/smartstore/menu/CustomerMenu.java create mode 100644 me/smartstore/menu/GroupMenu.java create mode 100644 me/smartstore/menu/Menu.java create mode 100644 me/smartstore/menu/OrderType.java create mode 100644 me/smartstore/menu/SummarizedMenu.java create mode 100644 me/smartstore/util/Message.java create mode 100644 me/smartstore/util/UtilMethod.java diff --git a/me/smartstore/Main.java b/me/smartstore/Main.java new file mode 100644 index 00000000..e8a48851 --- /dev/null +++ b/me/smartstore/Main.java @@ -0,0 +1,7 @@ +package me.smartstore; + +public class Main { + public static void main(String[] args) { + SmartStoreApplication.getInstance().test().run(); + } +} diff --git a/me/smartstore/SmartStoreApplication.java b/me/smartstore/SmartStoreApplication.java new file mode 100644 index 00000000..88bd97cd --- /dev/null +++ b/me/smartstore/SmartStoreApplication.java @@ -0,0 +1,81 @@ +package me.smartstore; + +import me.smartstore.customers.Customer; +import me.smartstore.customers.Customers; +import me.smartstore.groups.Group; +import me.smartstore.groups.GroupType; +import me.smartstore.groups.Groups; +import me.smartstore.groups.Parameter; +import me.smartstore.menu.CustomerMenu; +import me.smartstore.menu.GroupMenu; +import me.smartstore.menu.Menu; +import me.smartstore.menu.SummarizedMenu; + +public class SmartStoreApplication { + private static SmartStoreApplication smartStoreApp; + + public static SmartStoreApplication getInstance() { + if (smartStoreApp == null) + smartStoreApp = new SmartStoreApplication(); + return smartStoreApp; + } + + private final Groups allGroups = Groups.getInstance(); + private final Customers allCustomers = Customers.getInstance(); + private final Menu menu = Menu.getInstance(); + private final CustomerMenu customerMenu = CustomerMenu.getInstance(); + private final GroupMenu groupMenu = GroupMenu.getInstance(); + private final SummarizedMenu classifiedMenu = SummarizedMenu.getInstance(); + + public SmartStoreApplication test() { + allGroups.add(new Group(GroupType.GENERAL, new Parameter(Integer.valueOf(10), Integer.valueOf(100000)))); + allGroups.add(new Group(GroupType.VIP, new Parameter(Integer.valueOf(20), Integer.valueOf(200000)))); + allGroups.add(new Group(GroupType.VVIP, new Parameter(Integer.valueOf(30), Integer.valueOf(300000)))); + + for (int i = 0; i < 20; i++) { + allCustomers.add(new Customer( + Character.toString((char) (97 + i)), + "" + (char) (97 + i) + "123", + ((int) (Math.random() * 5.0D) + 1) * 10, + ((int) (Math.random() * 5.0D) + 1) * 100000)); + } + allCustomers.refresh(allGroups); + + return this; + } + + private void details() { + System.out.println("\n\n==========================================="); + System.out.println(" 스마트스토어_구조화"); + System.out.println(" @MebukiYamashi/Fastcampus_1st_ToyProject"); + System.out.println("===========================================\n"); + } + + public void run() { + details(); + + while (true) { + int choice = menu.displayMenus(new String[]{"매개변수 설정", "고객 데이터 관리", "데이터 분류/요약", "종료"}); + + if (choice == 1) { + groupMenu.manageParameterMenu(); + continue; + } + + if (choice == 2) { + customerMenu.manageCustomerMenu(); + continue; + } + + if (choice == 3) { + classifiedMenu.manageSummaryMenu(); + continue; + } + + if (choice == 4) { + System.out.println("\n프로그램을 종료합니다."); + return; + } + } + } +} diff --git a/me/smartstore/customers/ClassifiedCustomers.java b/me/smartstore/customers/ClassifiedCustomers.java new file mode 100644 index 00000000..bb8e740e --- /dev/null +++ b/me/smartstore/customers/ClassifiedCustomers.java @@ -0,0 +1,48 @@ +package me.smartstore.customers; + +import java.util.Arrays; +import java.util.Objects; +import me.smartstore.groups.Group; + +public class ClassifiedCustomers extends Customers { + private Group group; + + public ClassifiedCustomers() { + } + + public ClassifiedCustomers(Group group) { + this.group = group; + } + + public Group getGroup() { + return group; + } + + public void setGroup(Group group) { + this.group = group; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + ClassifiedCustomers that = (ClassifiedCustomers) o; + return Objects.equals(group, that.group); + } + + @Override + public int hashCode() { + return Objects.hash(group); + } + + @Override + public String toString() { + return "ClassifiedCustomers{" + + "group=" + group + + ", size=" + size + + ", customers=" + Arrays.toString(customers) + + "}"; + } +} diff --git a/me/smartstore/customers/ClassifiedCustomersGroup.java b/me/smartstore/customers/ClassifiedCustomersGroup.java new file mode 100644 index 00000000..0af68a68 --- /dev/null +++ b/me/smartstore/customers/ClassifiedCustomersGroup.java @@ -0,0 +1,94 @@ +package me.smartstore.customers; + +import java.util.Arrays; +import java.util.Comparator; +import me.smartstore.groups.GroupType; +import me.smartstore.groups.Parameter; + +public class ClassifiedCustomersGroup { + private static ClassifiedCustomersGroup classifiedCustomersGroup; + + private ClassifiedCustomers[] classifiedCustomers; + + public static ClassifiedCustomersGroup getInstance() { + if (classifiedCustomersGroup == null) + classifiedCustomersGroup = new ClassifiedCustomersGroup(); + return classifiedCustomersGroup; + } + + public ClassifiedCustomersGroup() { + this.classifiedCustomers = new ClassifiedCustomers[GroupType.size()]; + for (int i = 0; i < GroupType.size(); i++) + this.classifiedCustomers[i] = new ClassifiedCustomers(); + } + + public ClassifiedCustomers get(int i) { + return classifiedCustomers[i]; + } + + public void set(int i, ClassifiedCustomers customers) { + classifiedCustomers[i] = customers; + } + + public int size() { + return GroupType.size(); + } + + public void print() { + for (int i = 0; i < classifiedCustomers.length; i++) { + System.out.println("\n=============================="); + if (classifiedCustomers[i] == null) + return; + GroupType groupType = classifiedCustomers[i].getGroup().getType(); + Parameter parameter = classifiedCustomers[i].getGroup().getParam(); + System.out.printf("그룹: %s (시간: %d, 금액: %d)\n", groupType, + (parameter != null) ? parameter.getMinimumSpentTime() : null, + (parameter != null) ? parameter.getMinimumTotalPay() : null); + System.out.println("=============================="); + if (classifiedCustomers[i].isEmpty()) { + System.out.println("빈 값"); + } else { + classifiedCustomers[i].print(); + System.out.println("==============================\n"); + } + } + } + + public void sort(Comparator comparator) { + for (int i = 0; i < classifiedCustomersGroup.size(); i++) { + Customer[] customers = classifiedCustomersGroup.get(i).getCustomers(); + try { + if (comparator == null) { + Arrays.sort(customers); + } else { + Arrays.sort(customers, comparator); + } + classifiedCustomersGroup.get(i).setCustomers(customers); + } catch (NullPointerException e) { + System.out.println("빈 배열은 정렬할 수 없습니다."); + } + } + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + ClassifiedCustomersGroup that = (ClassifiedCustomersGroup) o; + return Arrays.equals(classifiedCustomers, that.classifiedCustomers); + } + + @Override + public int hashCode() { + return Arrays.hashCode(classifiedCustomers); + } + + @Override + public String toString() { + return "ClassifiedCustomersGroup{" + + "classifiedCustomers=" + Arrays.toString(classifiedCustomers) + + "}"; + } +} diff --git a/me/smartstore/customers/Customer.java b/me/smartstore/customers/Customer.java new file mode 100644 index 00000000..4df7ea37 --- /dev/null +++ b/me/smartstore/customers/Customer.java @@ -0,0 +1,96 @@ +package me.smartstore.customers; + +import java.util.Objects; +import me.smartstore.groups.Group; + +public class Customer implements Comparable { + private String userId; + private String name; + private Integer spentTime; + private Integer totalPay; + private Group group; + + public Customer() { + } + + public Customer(String name, String userId, int spentTime, int totalPay) { + this.name = name; + this.userId = userId; + this.spentTime = spentTime; + this.totalPay = totalPay; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public Integer getSpentTime() { + return spentTime; + } + + public void setSpentTime(Integer spentTime) { + this.spentTime = spentTime; + } + + public Integer getTotalPay() { + return totalPay; + } + + public void setTotalPay(Integer totalPay) { + this.totalPay = totalPay; + } + + public Group getGroup() { + return group; + } + + public void setGroup(Group group) { + this.group = group; + } + + @Override + public int compareTo(Customer o) { + int nameComparison = this.name.compareTo(o.name); + if (nameComparison != 0) + return nameComparison; + return this.userId.compareTo(o.userId); + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Customer customer = (Customer) o; + return Objects.equals(userId, customer.userId); + } + + @Override + public int hashCode() { + return Objects.hash(userId); + } + + @Override + public String toString() { + return "Customer{" + + "userId='" + userId + '\'' + + ", name='" + name + '\'' + + ", spentTime=" + spentTime + + ", totalPay=" + totalPay + + ", group=" + group + + "}"; + } +} diff --git a/me/smartstore/customers/Customers.java b/me/smartstore/customers/Customers.java new file mode 100644 index 00000000..6a76297a --- /dev/null +++ b/me/smartstore/customers/Customers.java @@ -0,0 +1,250 @@ +package me.smartstore.customers; + +import java.util.Arrays; +import me.smartstore.groups.Group; +import me.smartstore.groups.GroupType; +import me.smartstore.groups.Groups; + +public class Customers { + private static Customers allCustomers; + + public static Customers getInstance() { + if (allCustomers == null) + allCustomers = new Customers(); + return allCustomers; + } + + private final Groups allGroups = Groups.getInstance(); + + protected static final int DEFAULT_SIZE = 10; + + protected int capacity; + protected int size; + protected Customer[] customers; + + public Customers() { + this.customers = new Customer[DEFAULT_SIZE]; + this.capacity = DEFAULT_SIZE; + } + + public Customers(int initialCapacity) { + this.customers = new Customer[initialCapacity]; + this.capacity = initialCapacity; + } + + public Customers(Customer[] customers) { + this.customers = customers; + this.capacity = customers.length; + this.size = customers.length; + } + + public void setCustomers(Customer[] customers) { + this.customers = customers; + } + + public Customer[] getCustomers() { + return this.customers; + } + + public Customer[] getRealCustomers() { + int real = 0; + for (int i = 0; i < this.size; i++) { + if (this.customers[i] != null) + real++; + } + this.size = real; + return Arrays.copyOf(this.customers, real); + } + + public int getCapacity() { + return this.capacity; + } + + public void setCapacity(int capacity) { + this.capacity = capacity; + } + + public int getSize() { + return this.size; + } + + public void setSize(int size) { + this.size = size; + } + + public int capacity() { + return this.capacity; + } + + public int size() { + return this.size; + } + + public boolean isEmpty() { + return (this.size == 0); + } + + public void set(int index, Customer customer) { + if (index < 0 || index >= this.size) + return; + if (customer == null) + return; + this.customers[index] = customer; + } + + public Customer get(int index) { + if (index < 0 || index >= this.size) + return null; + return this.customers[index]; + } + + public int indexOf(Customer customer) { + if (customer == null) + return -1; + for (int i = 0; i < this.size; i++) { + if (this.customers[i] != null && this.customers[i].equals(customer)) + return i; + } + return -1; + } + + public void add(Customer customer) { + if (customer == null) + return; + if (this.size < this.capacity) { + this.customers[this.size] = customer; + this.size++; + } else { + grow(); + add(customer); + } + } + + public void add(int index, Customer customer) { + if (index < 0 || index > this.size) + return; + if (customer == null) + return; + if (this.size < this.capacity) { + for (int i = this.customers.length - 1; i >= index; i--) + this.customers[i + 1] = this.customers[i]; + this.customers[index] = customer; + this.size++; + } else { + grow(); + add(index, customer); + } + } + + public void grow() { + Customer[] copy = Arrays.copyOf(this.customers, this.customers.length); + this.capacity *= 2; + this.customers = new Customer[this.capacity]; + System.arraycopy(copy, 0, this.customers, 0, copy.length); + this.size = copy.length; + } + + public void pop(int index) { + if (this.size == 0) + return; + if (index < 0 || index >= this.size) + return; + this.customers[index] = null; + for (int j = index + 1; j < this.size; j++) + this.customers[j - 1] = this.customers[j]; + this.customers[this.size - 1] = null; + this.size--; + } + + public void pop() { + if (this.size == 0) + return; + this.customers[this.size - 1] = null; + this.size--; + } + + public void pop(Customer customer) { + if (this.size == 0) + return; + if (customer == null) + return; + pop(indexOf(customer)); + } + + public Customers trimToSize() { + Customer[] newCustomers = Arrays.copyOf(this.customers, this.size); + this.customers = newCustomers; + this.capacity = this.size; + return new Customers(newCustomers); + } + + public Customers findCustomers(GroupType type) { + Customers custs = new Customers(); + for (int i = 0; i < this.size; i++) { + Customer cust = get(i); + if (cust == null) + return null; + Group grp = cust.getGroup(); + if (type == GroupType.NONE) { + if (grp == null || grp.getType() == null || grp.getType() == GroupType.NONE) + custs.add(cust); + } else if (grp != null && grp.getType() == type) + { + custs.add(cust); + } + } + return custs; + } + + public Customers findCustomers(Group grp) { + if (grp != null) { + if (grp.getType() != null) + return findCustomers(grp.getType()); + System.out.println("Customers.findCustomers() Error: 그룹 타입이 존재하지 않습니다."); + return null; + } + System.out.println("Customers.findCustomers() Error: 그룹이 없습니다."); + return null; + } + + public void refresh(Groups groups) { + if (groups == null) + return; + for (int i = 0; i < this.size; i++) { + Customer cust = this.customers[i]; + cust.setGroup(groups.findGroupFor(cust)); + } + } + + public void print() { + for (int i = 0; i < this.size; i++) { + if (this.customers[i] != null) + System.out.printf("No. %4d => %s\n", i + 1, this.customers[i]); + } + } + + public ClassifiedCustomersGroup classified() { + ClassifiedCustomersGroup classifiedCusGroup = ClassifiedCustomersGroup.getInstance(); + for (int i = 0; i < this.allGroups.size(); i++) { + Group grp = this.allGroups.get(i); + Customer[] customers = grp.getCustomers(allCustomers).trimToSize().getCustomers(); + Customer[] copy = Arrays.copyOf(customers, customers.length); + ClassifiedCustomers classifiedCustomers = new ClassifiedCustomers(); + classifiedCustomers.setGroup(grp); + classifiedCustomers.setSize(copy.length); + classifiedCustomers.setCustomers(copy); + classifiedCusGroup.set(i, classifiedCustomers); + } + return classifiedCusGroup; + } + + @Override + public String toString() { + StringBuilder str = new StringBuilder(); + for (int i = 0; i < this.size; i++) { + if (this.customers[i] != null) + str.append(String.format("No. %4d => %s\n", i + 1, this.customers[i])); + } + return str.toString(); + } +} diff --git a/me/smartstore/exception/ArrayEmptyException.java b/me/smartstore/exception/ArrayEmptyException.java new file mode 100644 index 00000000..327a3d3e --- /dev/null +++ b/me/smartstore/exception/ArrayEmptyException.java @@ -0,0 +1,11 @@ +package me.smartstore.exception; + +public class ArrayEmptyException extends RuntimeException { + public ArrayEmptyException() { + super("고객이 없습니다. 다시 시도해주세요."); + } + + public ArrayEmptyException(String message) { + super(message); + } +} diff --git a/me/smartstore/exception/InputEmptyException.java b/me/smartstore/exception/InputEmptyException.java new file mode 100644 index 00000000..12892253 --- /dev/null +++ b/me/smartstore/exception/InputEmptyException.java @@ -0,0 +1,11 @@ +package me.smartstore.exception; + +public class InputEmptyException extends RuntimeException { + public InputEmptyException() { + super("입력값은 공백이 될 수 없습니다. 다시 시도해주세요."); + } + + public InputEmptyException(String message) { + super(message); + } +} diff --git a/me/smartstore/exception/InputEndException.java b/me/smartstore/exception/InputEndException.java new file mode 100644 index 00000000..68f0fcc6 --- /dev/null +++ b/me/smartstore/exception/InputEndException.java @@ -0,0 +1,11 @@ +package me.smartstore.exception; + +public class InputEndException extends RuntimeException { + public InputEndException() { + super("메뉴를 종료합니다."); + } + + public InputEndException(String message) { + super(message); + } +} diff --git a/me/smartstore/exception/InputFormatException.java b/me/smartstore/exception/InputFormatException.java new file mode 100644 index 00000000..9bb632cc --- /dev/null +++ b/me/smartstore/exception/InputFormatException.java @@ -0,0 +1,11 @@ +package me.smartstore.exception; + +public class InputFormatException extends RuntimeException { + public InputFormatException() { + super("입력된 값이 잘못된 형식으로 되어있습니다. 다시 시도해주세요."); + } + + public InputFormatException(String message) { + super(message); + } +} diff --git a/me/smartstore/exception/InputRangeException.java b/me/smartstore/exception/InputRangeException.java new file mode 100644 index 00000000..4dc48788 --- /dev/null +++ b/me/smartstore/exception/InputRangeException.java @@ -0,0 +1,11 @@ +package me.smartstore.exception; + +public class InputRangeException extends RuntimeException { + public InputRangeException() { + super("잘못된 값입니다. 다시 시도해주세요."); + } + + public InputRangeException(String message) { + super(message); + } +} diff --git a/me/smartstore/exception/InputTypeException.java b/me/smartstore/exception/InputTypeException.java new file mode 100644 index 00000000..80b98ab6 --- /dev/null +++ b/me/smartstore/exception/InputTypeException.java @@ -0,0 +1,11 @@ +package me.smartstore.exception; + +public class InputTypeException extends RuntimeException { + public InputTypeException() { + super("잘못된 값입니다. 다시 시도해주세요."); + } + + public InputTypeException(String message) { + super(message); + } +} diff --git a/me/smartstore/groups/Group.java b/me/smartstore/groups/Group.java new file mode 100644 index 00000000..7d41211e --- /dev/null +++ b/me/smartstore/groups/Group.java @@ -0,0 +1,66 @@ +package me.smartstore.groups; + +import java.util.Objects; +import me.smartstore.customers.Customers; + +public class Group { + private GroupType type; + private Parameter param; + + public Group() { + this(null, null); + } + + public Group(GroupType type, Parameter param) { + this.type = type; + this.param = param; + } + + public GroupType getType() { + return type; + } + + public void setType(GroupType type) { + this.type = type; + } + + public Parameter getParam() { + return param; + } + + public void setParam(Parameter param) { + this.param = param; + } + + public Customers getCustomers(Customers allCustomers) { + return allCustomers.findCustomers(this); + } + + public void update(GroupType type, Parameter param) { + this.type = type; + this.param = param; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Group group = (Group) o; + return type == group.type && Objects.equals(param, group.param); + } + + @Override + public int hashCode() { + return Objects.hash(type, param); + } + + @Override + public String toString() { + if (type == null) + return "그룹이 없어요."; + return (param == null) ? ("GroupType: " + type + "\nParameter: null") + : ("GroupType: " + type + "\nParameter: " + param); + } +} diff --git a/me/smartstore/groups/GroupType.java b/me/smartstore/groups/GroupType.java new file mode 100644 index 00000000..8f7ba35c --- /dev/null +++ b/me/smartstore/groups/GroupType.java @@ -0,0 +1,42 @@ +package me.smartstore.groups; + +public enum GroupType { + NONE("비회원"), + GENERAL("일반"), + VIP("우수"), + VVIP("최우수"), + N("비회원"), + G("일반"), + V("우수"), + VV("최우수"); + + String groupType = ""; + + GroupType(String groupType) { + this.groupType = groupType; + } + + public String getGroupType() { + return this.groupType; + } + + public void setGroupType(String groupType) { + this.groupType = groupType; + } + + public GroupType replaceFullName() { + if (this == N) + return NONE; + if (this == G) + return GENERAL; + if (this == V) + return VIP; + if (this == VV) + return VVIP; + return this; + } + + public static int size() { + return (values()).length / 2; + } +} diff --git a/me/smartstore/groups/Groups.java b/me/smartstore/groups/Groups.java new file mode 100644 index 00000000..95cc6a87 --- /dev/null +++ b/me/smartstore/groups/Groups.java @@ -0,0 +1,108 @@ +package me.smartstore.groups; + +import me.smartstore.customers.Customer; +import me.smartstore.util.UtilMethod; + +public class Groups { + private static Groups allGroups; + + private int size; + private Group[] groups; + + public static Groups getInstance() { + if (allGroups == null) + allGroups = new Groups(); + return allGroups; + } + + public Groups() { + this.groups = new Group[GroupType.size()]; + initialize(); + } + + public Group[] getGroups() { + return groups; + } + + public void setGroups(Group[] groups) { + this.groups = groups; + } + + public int size() { + return size; + } + + public int length() { + return groups.length; + } + + public boolean isEmpty() { + return (size == 0); + } + + public void initialize() { + for (int i = 0; i < GroupType.size(); i++) { + groups[i] = new Group(GroupType.values()[i], null); + size++; + } + } + + public void add(Group group) { + Group grp = find(group.getType()); + if (grp != null) { + update(group); + } else { + groups[size] = group; + size++; + } + } + + public Group get(int i) { + return groups[i]; + } + + public void update(Group group) { + Group grp = find(group.getType()); + if (grp != null) + grp.setParam(group.getParam()); + } + + public void print() { + for (int i = 0; i < size; i++) { + if (groups[i] != null) + System.out.println(groups[i]); + } + } + + public Group find(GroupType groupType) { + for (Group grp : groups) { + if (grp.getType() == groupType) + return grp; + } + return null; + } + + public Group findGroupFor(Customer customer) { + if (groups == null) + return null; + if (UtilMethod.isAnyNUll(new Object[]{customer, customer.getSpentTime(), customer.getTotalPay()})) + return null; + for (int i = size - 1; i >= 0; i--) { + if (!UtilMethod.isAnyNUll(new Object[]{groups[i], groups[i].getParam()})) { + Parameter param = groups[i].getParam(); + if (!UtilMethod.isAnyNUll(new Object[]{param, param.getMinimumSpentTime(), param.getMinimumTotalPay()})) + if (customer.getSpentTime().intValue() >= param.getMinimumSpentTime().intValue() && customer + .getTotalPay().intValue() >= param.getMinimumTotalPay().intValue()) + return groups[i]; + } + } + return null; + } + + public String toString() { + String str = ""; + for (int i = 0; i < size; i++) + str = str + " " + str + "\n"; + return str; + } +} diff --git a/me/smartstore/groups/Parameter.java b/me/smartstore/groups/Parameter.java new file mode 100644 index 00000000..2e0ceec7 --- /dev/null +++ b/me/smartstore/groups/Parameter.java @@ -0,0 +1,50 @@ +package me.smartstore.groups; + +import java.util.Objects; + +public class Parameter { + private Integer minimumSpentTime; + private Integer minimumTotalPay; + + public Parameter() { + } + + public Parameter(Integer minimumSpentTime, Integer minimumTotalPay) { + this.minimumSpentTime = minimumSpentTime; + this.minimumTotalPay = minimumTotalPay; + } + + public Integer getMinimumSpentTime() { + return minimumSpentTime; + } + + public void setMinimumSpentTime(Integer minimumSpentTime) { + this.minimumSpentTime = minimumSpentTime; + } + + public Integer getMinimumTotalPay() { + return minimumTotalPay; + } + + public void setMinimumTotalPay(Integer minimumTotalPay) { + this.minimumTotalPay = minimumTotalPay; + } + + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Parameter parameter = (Parameter) o; + return Objects.equals(minimumSpentTime, parameter.minimumSpentTime) && + Objects.equals(minimumTotalPay, parameter.minimumTotalPay); + } + + public int hashCode() { + return Objects.hash(minimumSpentTime, minimumTotalPay); + } + + public String toString() { + return "매개변수{최소 소비시간 =" + minimumSpentTime + ", 소비 금액 =" + minimumTotalPay + "}"; + } +} diff --git a/me/smartstore/menu/CustomerMenu.java b/me/smartstore/menu/CustomerMenu.java new file mode 100644 index 00000000..7a56a6be --- /dev/null +++ b/me/smartstore/menu/CustomerMenu.java @@ -0,0 +1,273 @@ +package me.smartstore.menu; + +import me.smartstore.customers.Customer; +import me.smartstore.customers.Customers; +import me.smartstore.exception.ArrayEmptyException; +import me.smartstore.exception.InputEmptyException; +import me.smartstore.exception.InputEndException; +import me.smartstore.exception.InputRangeException; +import me.smartstore.groups.Group; +import me.smartstore.groups.Groups; + +public class CustomerMenu extends Menu { + private static CustomerMenu customerMenu; + + public static CustomerMenu getInstance() { + if (customerMenu == null) + customerMenu = new CustomerMenu(); + return customerMenu; + } + + private Groups allGroups = Groups.getInstance(); + private Customers allCustomers = Customers.getInstance(); + + public void manageCustomerMenu() { + while (true) { + int choice = displayMenus(new String[] { "고객 데이터 추가", "고객 데이터 보기", "고객 데이터 갱신", + "고객 데이터 삭제", "되돌아가기" }); + if (choice == 1) { + int size = 0; + size = getCustomerSizeToAdd(); + setCustomerData(size); + continue; + } + if (choice == 2) { + viewCustomerData(); + continue; + } + if (choice == 3) { + updateCustomerData(); + continue; + } + if (choice == 4) { + deleteCustomerData(); + continue; + } + if (choice == 5) + break; + } + } + + public void setCustomerData(int size) { + for (int i = 0; i < size; i++) { + Customer customer = new Customer(); + System.out.println("\n====== 고객 " + (i + 1) + " 정보 ======"); + while (true) { + int choice = displayMenus( + new String[] { "고객 이름", "ID", "상주 시간", "소비 금액", "뒤로" }); + if (choice == 1) { + setCustomerName(customer); + continue; + } + if (choice == 2) { + setCustomerUserId(customer); + continue; + } + if (choice == 3) { + setCustomerSpentTime(customer); + continue; + } + if (choice == 4) { + setCustomerTotalPay(customer); + continue; + } + if (choice == 5) + break; + } + Group grp = allGroups.findGroupFor(customer); + if (grp == null) { + customer.setGroup(null); + } else if (!grp.equals(customer.getGroup())) { + customer.setGroup(grp); + } + allCustomers.add(customer); + } + } + + public void viewCustomerData() { + if (allCustomers.size() == 0) { + System.out.println("고객이 없습니다."); + return; + } + System.out.println("\n======== 고객정보 ========"); + for (int i = 0; i < allCustomers.size(); i++) { + Customer cust = allCustomers.get(i); + if (cust != null) { + System.out.println("No. " + (i + 1) + " => " + cust); + } else { + System.out.println("null"); + } + } + } + + public void updateCustomerData() { + viewCustomerData(); + int custNo = 0; + try { + custNo = findCustomer(); + } catch (ArrayEmptyException | InputEndException e) { + return; + } + Customer customer = allCustomers.get(custNo - 1); + if (customer == null) + return; + while (true) { + int choice = displayMenus( + new String[] { "고객 이름", "ID", "상주 시간", "소비 금액", "뒤로" }); + if (choice == 1) { + setCustomerName(customer); + continue; + } + if (choice == 2) { + setCustomerUserId(customer); + continue; + } + if (choice == 3) { + setCustomerSpentTime(customer); + continue; + } + if (choice == 4) { + setCustomerTotalPay(customer); + continue; + } + if (choice == 5) + break; + } + Group grp = allGroups.findGroupFor(customer); + if (grp == null) { + customer.setGroup(null); + } else if (!grp.equals(customer.getGroup())) { + customer.setGroup(grp); + } + } + + public void deleteCustomerData() { + viewCustomerData(); + int custNo = 0; + try { + custNo = findCustomer(); + } catch (ArrayEmptyException | InputEndException e) { + return; + } + Customer customer = allCustomers.get(custNo - 1); + System.out.println(customer); + allCustomers.pop(custNo - 1); + viewCustomerData(); + } + + private int getCustomerSizeToAdd() { + while (true) { + try { + System.out.print("입력할 고객 수 : "); + int size = Integer.parseInt(nextLine("END")); + if (size < 0) + throw new InputRangeException(); + return size; + } catch (NumberFormatException e) { + System.out.println("잘못된 포맷입니다. 다시 시도하세요."); + } catch (InputRangeException e) { + System.out.println("잘못된 입력입니다. 다시 시도하세요."); + } catch (InputEndException e) { + System.out.println("메뉴로 돌아갑니다."); + return -1; + } + } + } + +public void setCustomerName(Customer customer) { + while (true) { + try { + System.out.print("\n고객 이름 입력 : "); + String name = nextLine("END"); + if (name == null || name.equals("")) + throw new InputEmptyException(); + customer.setName(name); + return; + } catch (InputEmptyException e) { + System.out.println("입력값은 빈 값이 될 수 없습니다.. 다시 시도하세요."); + } catch (InputEndException e) { + System.out.println("메뉴로 돌아갑니다."); + break; + } + } + } + + public void setCustomerUserId(Customer customer) { + while (true) { + try { + System.out.print("\n고객 ID 입력 : "); + String userId = nextLine("END"); + if (userId == null || userId.equals("")) + throw new InputEmptyException(); + customer.setUserId(userId); + return; + } catch (InputEmptyException e) { + System.out.println("입력값은 빈 값이 될 수 없습니다.. 다시 시도하세요."); + } catch (InputEndException e) { + System.out.println("메뉴로 돌아갑니다."); + break; + } + } + } + + public void setCustomerSpentTime(Customer customer) { + while (true) { + try { + System.out.print("\n고객 상주 시간 : "); + int spentTime = Integer.parseInt(nextLine("END")); + if (spentTime < 0) + throw new InputRangeException(); + customer.setSpentTime(Integer.valueOf(spentTime)); + return; + } catch (InputRangeException e) { + System.out.println("입력값은 빈 값이 될 수 없습니다.. 다시 시도하세요."); + } catch (InputEndException e) { + System.out.println("메뉴로 돌아갑니다."); + break; + } + } + } + + public void setCustomerTotalPay(Customer customer) { + while (true) { + try { + System.out.print("\n입력된 고객의 총 사용 금액은 : "); + int totalPay = Integer.parseInt(nextLine("END")); + if (totalPay < 0) + throw new InputRangeException(); + customer.setTotalPay(Integer.valueOf(totalPay)); + return; + } catch (NumberFormatException e) { + System.out.println("잘못된 포맷입니다. 다시 시도하세요."); + } catch (InputRangeException e) { + System.out.println("잘못된 입력입니다. 다시 시도하세요."); + } catch (InputEndException e) { + System.out.println("메뉴로 돌아갑니다."); + break; + } + } + } + + public int findCustomer() throws ArrayEmptyException, InputEndException { + int size = allCustomers.size(); + if (size == 0) + throw new ArrayEmptyException(); + while (true) { + try { + System.out.print("\n어느 고객 ( 1 ~ " + size + " )? "); + int custNo = Integer.parseInt(nextLine()); + if (custNo < 1 || custNo > size) + throw new InputRangeException(); + return custNo; + } catch (NumberFormatException e) { + System.out.println("\n잘못된 포맷입니다. 다시 시도하세요."); + } catch (InputRangeException e) { + System.out.println("\n잘못된 입력입니다. 다시 시도하세요."); + } catch (InputEndException e) { + System.out.println("메뉴로 돌아갑니다."); + break; + } + } + return size; + } +} diff --git a/me/smartstore/menu/GroupMenu.java b/me/smartstore/menu/GroupMenu.java new file mode 100644 index 00000000..d09e8742 --- /dev/null +++ b/me/smartstore/menu/GroupMenu.java @@ -0,0 +1,215 @@ +package me.smartstore.menu; + +import me.smartstore.customers.Customers; +import me.smartstore.exception.InputEmptyException; +import me.smartstore.exception.InputEndException; +import me.smartstore.exception.InputRangeException; +import me.smartstore.groups.Group; +import me.smartstore.groups.GroupType; +import me.smartstore.groups.Groups; +import me.smartstore.groups.Parameter; + +public class GroupMenu extends Menu { + private static GroupMenu instance; + + public static GroupMenu getInstance() { + if (instance == null) + instance = new GroupMenu(); + return instance; + } + + private Groups allGroups = Groups.getInstance(); + private Customers allCustomers = Customers.getInstance(); + + public String chooseGroup() { + while (true) { + try { + System.out.print("소비자 그룹 선택(일반 (G), 우수 (V), 최우수 (VV)) : "); + String choice = nextLine("END"); + if (choice.isEmpty()) + throw new InputEmptyException(); + return choice; + } catch (InputEmptyException e) { + System.out.println("입력값은 빈 값이 될 수 없습니다."); + } catch (IllegalArgumentException e) { + System.out.println("잘못된 입력입니다. 다시 시도해주세요."); + } catch (InputEndException e) { + System.out.println("메뉴로 돌아갑니다."); + return null; + } + } + } + + public void manageParameterMenu() { + while (true) { + int choice = displayMenus(new String[] { "매개변수 설정", "매개변수 확인", "매개변수 갱신", "되돌아가기" }); + switch (choice) { + case 1: + setParameter(); + break; + + case 2: + viewParameter(); + break; + + case 3: + updateParameter(); + break; + + case 4: + return; + + default: + System.out.println("잘못 고르셨습니다. 다시 시도하세요."); + } + } + } + + public void setParameter() { + while (true) { + GroupType groupType; + String strGroup = chooseGroup(); + if (strGroup == null) + return; + try { + groupType = GroupType.valueOf(strGroup).replaceFullName(); + } catch (IllegalArgumentException e) { + System.out.println("\n잘못 입력하셨습니다. 다시 시도하세요."); + continue; + } + Group grp = allGroups.find(groupType); + if (grp != null && grp.getParam() != null) { + System.out.println("\n" + grp.getType() + "그룹이 존재합니다."); + System.out.println("\n" + grp); + continue; + } + Parameter param = new Parameter(); + while (true) { + int choice = displayMenus(new String[] { "최소 소비시간", "최소 소비금액", "되돌아가기" }); + switch (choice) { + case 1: + setParameterMinimumSpentTime(param); + break; + + case 2: + setParameterMinimumTotalPay(param); + break; + + case 3: + break; + + default: + System.out.println("잘못 선택하셨습니다. 다시 시도하세요."); + } + if (choice == 3) + break; + } + allGroups.add(new Group(groupType, param)); + allCustomers.refresh(allGroups); + System.out.println("\n" + grp); + } + } + + public void viewParameter() { + while (true) { + GroupType groupType; + String strGroup = chooseGroup(); + if (strGroup == null) + return; + try { + groupType = GroupType.valueOf(strGroup).replaceFullName(); + } catch (IllegalArgumentException e) { + System.out.println("\n입력 형식이 잘못되었습니다. 다시 시도해주세요."); + continue; + } + Group grp = allGroups.find(groupType); + System.out.println(); + System.out.println(grp); + } + } + + public void updateParameter() { + while (true) { + GroupType groupType; + String strGroup = chooseGroup(); + if (strGroup == null) + return; + try { + groupType = GroupType.valueOf(strGroup).replaceFullName(); + } catch (IllegalArgumentException e) { + System.out.println("\n잘못 입력하셨습니다. 다시 시도해주세요."); + return; + } + Group grp = allGroups.find(groupType); + if (grp.getParam() == null) { + System.out.println("\n매개변수가 없습니다. 먼저 설정 후 시도해주세요."); + return; + } + System.out.println("\n" + grp); + Parameter param = grp.getParam(); + while (true) { + int choice = displayMenus(new String[] { "최소 소비시간", "최소 소비금액", "되돌아가기" }); + switch (choice) { + case 1: + setParameterMinimumSpentTime(param); + break; + + case 2: + setParameterMinimumTotalPay(param); + break; + + case 3: + break; + + default: + System.out.println("잘못 선택하셨습니다. 다시 시도해주세요."); + } + if (choice == 3) + break; + } + allGroups.update(new Group(groupType, param)); + allCustomers.refresh(allGroups); + System.out.println("\n" + grp); + } + } + + public void setParameterMinimumSpentTime(Parameter param) { + while (true) { + try { + System.out.print("\n최소 소비금액 : "); + int minimumSpentTime = Integer.parseInt(nextLine("END")); + if (minimumSpentTime < 0) + throw new InputRangeException(); + param.setMinimumSpentTime(Integer.valueOf(minimumSpentTime)); + return; + } catch (NumberFormatException e) { + System.out.println("입력값은 빈 값이 될 수 없습니다."); + } catch (InputRangeException e) { + System.out.println("잘못된 입력입니다. 다시 시도해주세요."); + } catch (InputEndException e) { + System.out.println("메뉴로 돌아갑니다."); + break; + } + } + } + +public void setParameterMinimumTotalPay(Parameter param) { + while (true) { + try { + System.out.print("\n최소 소비금액 : "); + int minimumTotalPay = Integer.parseInt(nextLine("END")); + if (minimumTotalPay < 0) + throw new InputRangeException(); + param.setMinimumTotalPay(Integer.valueOf(minimumTotalPay)); + return; + } catch (NumberFormatException e) { + System.out.println("잘못 입력되었습니다. 다시 시도해주세요."); + } catch (InputRangeException e) { + System.out.println("잘못 입력되었습니다. 다시 시도해주세요."); + } catch (InputEndException e) { + System.out.println("메뉴로 돌아갑니다."); + break; + } + } + } +} diff --git a/me/smartstore/menu/Menu.java b/me/smartstore/menu/Menu.java new file mode 100644 index 00000000..31eb0450 --- /dev/null +++ b/me/smartstore/menu/Menu.java @@ -0,0 +1,68 @@ +package me.smartstore.menu; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import me.smartstore.exception.InputEndException; +import me.smartstore.exception.InputRangeException; + +public class Menu { + private static Menu menu; + private BufferedReader reader; + + public static Menu getInstance() { + if (menu == null) + menu = new Menu(); + return menu; + } + + public Menu() { + reader = new BufferedReader(new InputStreamReader(System.in)); + } + + public String nextLine() { + try { + String str = reader.readLine().toUpperCase(); + String[] strings = str.split("\\s"); + return (strings.length > 1) ? "" : str; + } catch (IOException e) { + e.printStackTrace(); + return ""; + } + } + + public String nextLine(String messageForEnd) throws InputEndException { + System.out.println("\n**END를 누르면 닫습니다.**"); + try { + String str = reader.readLine().toUpperCase(); + if (str.equals(messageForEnd)) + throw new InputEndException(); + String[] strings = str.split("\\s"); + return (strings.length > 1) ? "" : str; + } catch (IOException e) { + e.printStackTrace(); + return ""; + } + } + + public int displayMenus(String[] menus) { + while (true) { + try { + System.out.println("\n=============================="); + for (int i = 0; i < menus.length; i++) { + System.out.printf(" %d. %s\n", i + 1, menus[i]); + } + System.out.println("=============================="); + System.out.print("하나를 선택해주세요. : "); + int choice = Integer.parseInt(nextLine()); + if (choice >= 1 && choice <= menus.length) + return choice; + throw new InputRangeException(); + } catch (NumberFormatException e) { + System.out.println("입력 포맷이 잘못되었습니다. 다시 시도해주세요."); + } catch (InputRangeException e) { + System.out.println("잘못 입력하셨습니다. 다시 시도해주세요."); + } + } + } +} diff --git a/me/smartstore/menu/OrderType.java b/me/smartstore/menu/OrderType.java new file mode 100644 index 00000000..06fcf564 --- /dev/null +++ b/me/smartstore/menu/OrderType.java @@ -0,0 +1,34 @@ +package me.smartstore.menu; + +public enum OrderType { + ASCENDING("오름차순"), + DESCENDING("내림차순"), + A("A"), + D("D"); + + private String sortType; + + OrderType(String sortType) { + this.sortType = sortType; + } + + public String getSortType() { + return this.sortType; + } + + public void setSortType(String sortType) { + this.sortType = sortType; + } + + public OrderType replaceFullName() { + if (this == A) + return ASCENDING; + if (this == D) + return DESCENDING; + return this; + } + + public static int size() { + return values().length / 2; + } +} diff --git a/me/smartstore/menu/SummarizedMenu.java b/me/smartstore/menu/SummarizedMenu.java new file mode 100644 index 00000000..abdcbedf --- /dev/null +++ b/me/smartstore/menu/SummarizedMenu.java @@ -0,0 +1,110 @@ +package me.smartstore.menu; + +import java.util.Comparator; +import me.smartstore.customers.ClassifiedCustomersGroup; +import me.smartstore.customers.Customer; +import me.smartstore.customers.Customers; +import me.smartstore.exception.InputEmptyException; +import me.smartstore.exception.InputEndException; +import me.smartstore.exception.InputRangeException; + +public class SummarizedMenu extends Menu { + private static SummarizedMenu summarizedMenu; + + public static SummarizedMenu getInstance() { + if (summarizedMenu == null) + summarizedMenu = new SummarizedMenu(); + return summarizedMenu; + } + + private Customers allCustomers = Customers.getInstance(); + + private ClassifiedCustomersGroup classifiedCusGroup = ClassifiedCustomersGroup.getInstance(); + + public void manageSummaryMenu() { + classifiedCusGroup = allCustomers.classified(); + while (true) { + int choice = displayMenus(new String[] { + "요약", + "요약(이름별 정렬)", + "요약(상주시간별 정렬)", + "요약(사용금액별 정렬)", + "되돌아가기" + }); + if (choice == 1) { + displaySummery(); + } else if (choice == 2) { + manageSort(Comparator.comparing(Customer::getName).thenComparing(Customer::getUserId)); + } else if (choice == 3) { + manageSort(Comparator.comparing(Customer::getSpentTime).thenComparing(Customer::getName)); + } else if (choice == 4) { + manageSort(Comparator.comparing(Customer::getTotalPay).thenComparing(Customer::getName)); + } else if (choice == 5) { + break; + } + } + } + + public void displaySummery() { + if (classifiedCusGroup == null) { + System.out.println("입력값은 공백이 될 수 없습니다. 다시 시도해주세요."); + return; + } + classifiedCusGroup.print(); + } + + public void manageSort(Comparator comparator) { + while (true) { + String strOrder = chooseSortOrder(); + if (strOrder == null) { + return; + } + if (strOrder.equals("END")) { + return; + } + try { + OrderType orderType = OrderType.valueOf(strOrder).replaceFullName(); + if (orderType == OrderType.ASCENDING) { + classifiedCusGroup.sort(comparator); + } else if (orderType == OrderType.DESCENDING) { + classifiedCusGroup.sort(comparator.reversed()); + } else { + throw new InputRangeException(); + } + } catch (IllegalArgumentException | InputRangeException e) { + System.out.println("\n잘못 입력하셨습니다. 다시 시도하세요."); + } + displaySummery(); + } + } + + public String chooseSortOrder() { + while (true) { + try { + System.out.print("정렬순서 (ASCENDING (A), DESCENDING (D)): "); + String choice = nextLine("END"); + if (choice.equals("")) { + throw new InputEmptyException(); + } + try { + OrderType orderType = OrderType.valueOf(choice).replaceFullName(); + for (OrderType value : OrderType.values()) { + if (orderType == value) { + return choice; + } + } + throw new InputRangeException(); + } catch (IllegalArgumentException e) { + System.out.println("입력값은 공백이 될 수 없습니다. 다시 시도해주세요."); + } + } catch (InputEmptyException e) { + System.out.println("입력값은 공백이 될 수 없습니다. 다시 시도해주세요."); + } catch (InputRangeException e) { + System.out.println("잘못 입력하셨습니다. 다시 시도해주세요."); + } catch (InputEndException e) { + System.out.println("메뉴를 닫습니다."); + return null; + } + } + } +} diff --git a/me/smartstore/util/Message.java b/me/smartstore/util/Message.java new file mode 100644 index 00000000..eed5b56a --- /dev/null +++ b/me/smartstore/util/Message.java @@ -0,0 +1,13 @@ +package me.smartstore.util; + +public interface Message { + public static final String ERR_MSG_INVALID_ARR_EMPTY = "고객이 없습니다. 새로운 값을 입력해주세요."; + public static final String ERR_MSG_NULL_ARR_ELEMENT = "배열 내 원소가 없습니다. 새로운 값을 입력해주세요."; + public static final String ERR_MSG_INVALID_INPUT_NULL = "빈 값입니다. 새로운 값을 입력해주세요."; + public static final String ERR_MSG_INVALID_INPUT_EMPTY = "빈 값입니다. 새로운 값을 입력해주세요."; + public static final String ERR_MSG_INVALID_INPUT_RANGE = "잘못된 데이터 형식입니다. 새로운 값을 입력해주세요."; + public static final String ERR_MSG_INVALID_INPUT_TYPE = "잘못된 데이터 형식입니다. 새로운 값을 입력해주세요."; + public static final String ERR_MSG_INVALID_INPUT_FORMAT = "잘못된 데이터 형식입니다. 새로운 값을 입력해주세요."; + public static final String ERR_MSG_INPUT_END = "값에는 END를 입력할 수 없습니다. 새로운 값을 입력해주세요."; + public static final String END_MSG = "END"; +} diff --git a/me/smartstore/util/UtilMethod.java b/me/smartstore/util/UtilMethod.java new file mode 100644 index 00000000..99241e97 --- /dev/null +++ b/me/smartstore/util/UtilMethod.java @@ -0,0 +1,14 @@ +package me.smartstore.util; + +import java.util.Arrays; +import java.util.Objects; + +public class UtilMethod { + public static boolean isAnyNUll(Object... objects) { + return Arrays.stream(objects).anyMatch(Objects::isNull); + } + + public static boolean isAllNUll(Object... objects) { + return Arrays.stream(objects).allMatch(Objects::isNull); + } +}