diff --git a/me/day05/practice/AuthMethod.java b/me/day05/practice/AuthMethod.java new file mode 100644 index 0000000..874b313 --- /dev/null +++ b/me/day05/practice/AuthMethod.java @@ -0,0 +1,5 @@ +package me.day05.practice; + +public enum AuthMethod { + FINGERPRINT_AUTHENTICATION, PATTERN_AUTHENTICATION, PIN_AUTHENTICATION, FACIAL_AUTHENTICATION +} diff --git a/me/day05/practice/Company.java b/me/day05/practice/Company.java new file mode 100644 index 0000000..eaf295f --- /dev/null +++ b/me/day05/practice/Company.java @@ -0,0 +1,5 @@ +package me.day05.practice; + +public enum Company { + SAMSUNG, LG, APPLE +} diff --git a/me/day05/practice/Electronic.java b/me/day05/practice/Electronic.java new file mode 100644 index 0000000..bcb9b20 --- /dev/null +++ b/me/day05/practice/Electronic.java @@ -0,0 +1,95 @@ +package me.day05.practice; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.Objects; + +public class Electronic { + private static Long registerNo; + private String productNo; + private String modelName; + private Company companyName; + private LocalDate dateOfMade; + private AuthMethod[] authMethods; + + public Electronic() { + if (registerNo == null) { + registerNo = 0L; + } + this.productNo = LocalDate.now().format(DateTimeFormatter.ofPattern("YYMMdd")) + + (String.format("%04d", ++registerNo)); + } + + public static Long getRegisterNo() { + return registerNo; + } + + public String getProductNo() { + return productNo; + } + + public void setProductNo(String productNo) { + this.productNo = productNo; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public Company getCompanyName() { + return companyName; + } + + public void setCompanyName(Company companyName) { + this.companyName = companyName; + } + + public LocalDate getDateOfMade() { + return dateOfMade; + } + + public void setDateOfMade(LocalDate dateOfMade) { + this.dateOfMade = dateOfMade; + } + + public AuthMethod[] getAuthMethods() { + return authMethods; + } + + public void setAuthMethods(AuthMethod[] authMethods) { + this.authMethods = authMethods; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Electronic that = (Electronic)o; + return productNo.equals(that.productNo) && Objects.equals(modelName, that.modelName) + && companyName == that.companyName && Objects.equals(dateOfMade, that.dateOfMade) + && Arrays.equals(authMethods, that.authMethods); + } + + @Override + public int hashCode() { + return Objects.hash(productNo); + } + + @Override + public String toString() { + return "Electronic{" + + "productNo='" + productNo + '\'' + + ", modelName='" + modelName + '\'' + + ", companyName=" + companyName + + ", dateOfMade=" + dateOfMade + + ", authMethods=" + Arrays.toString(authMethods) + + '}'; + } +} diff --git a/me/day05/practice/Electronics.java b/me/day05/practice/Electronics.java new file mode 100644 index 0000000..cfb6971 --- /dev/null +++ b/me/day05/practice/Electronics.java @@ -0,0 +1,48 @@ +package me.day05.practice; + +import java.util.Arrays; + +public class Electronics { + private static Electronics electronics; + private Electronic[] electronicList; + + private Electronics() { + + } + + public static Electronics getInstance() { + if (electronics == null) { + electronics = new Electronics(); + } + return Electronics.electronics; + } + + public Electronic findByProductNo(String productNo) { + return Arrays.stream(this.electronicList) + .filter(electronic -> electronic.getProductNo().equals(productNo)) + .findFirst() + .orElse(null); + } + + Electronic[] groupByCompany(Company company) { + return Arrays.stream(this.electronicList) + .filter(electronic -> electronic.getCompanyName().equals(company)) + .toArray(Electronic[]::new); + } + + Electronic[] groupByAuthMethod(AuthMethod authMethod) { + return Arrays.stream(this.electronicList) + .filter( + electronic -> Arrays.stream(electronic.getAuthMethods()) + .anyMatch(authMethods -> authMethods.equals(authMethod)) + ).toArray(Electronic[]::new); + } + + public Electronic[] getElectronicList() { + return electronicList; + } + + public void setElectronicList(Electronic[] electronicList) { + this.electronicList = electronicList; + } +} diff --git a/me/day05/practice/User.java b/me/day05/practice/User.java new file mode 100644 index 0000000..e7709ab --- /dev/null +++ b/me/day05/practice/User.java @@ -0,0 +1,109 @@ +package me.day05.practice; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.Objects; + +public class User implements Cloneable { + private String userId; + private String userPassword; + private String userPhoneNumber; + private String email; + private LocalDate userBirthDate; + private Electronic[] electronicDevices; + private LocalDateTime registerTime; + + public User() { + this.registerTime = LocalDateTime.now(); + } + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getUserPassword() { + return userPassword; + } + + public void setUserPassword(String userPassword) { + this.userPassword = userPassword; + } + + public String getUserPhoneNumber() { + return userPhoneNumber; + } + + public void setUserPhoneNumber(String userPhoneNumber) { + this.userPhoneNumber = userPhoneNumber; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public LocalDate getUserBirthDate() { + return userBirthDate; + } + + public void setUserBirthDate(LocalDate userBirthDate) { + this.userBirthDate = userBirthDate; + } + + public Electronic[] getElectronicDevices() { + return electronicDevices; + } + + public void setElectronicDevices(Electronic[] electronicDevices) { + this.electronicDevices = electronicDevices; + } + + public LocalDateTime getRegisterTime() { + return registerTime; + } + + public void setRegisterTime(LocalDateTime registerTime) { + this.registerTime = registerTime; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + User user = (User)o; + return userId.equals(user.userId); + } + + @Override + public int hashCode() { + return Objects.hash(userId); + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + @Override + public String toString() { + return "User{" + + "userId='" + userId + '\'' + + ", userPassword='" + userPassword + '\'' + + ", userPhoneNumber='" + userPhoneNumber + '\'' + + ", email='" + email + '\'' + + ", userBirthDate=" + userBirthDate + + ", electronicDevices=" + Arrays.toString(electronicDevices) + + ", registerTime=" + registerTime + + '}'; + } +} diff --git a/me/day05/practice/Users.java b/me/day05/practice/Users.java new file mode 100644 index 0000000..487f485 --- /dev/null +++ b/me/day05/practice/Users.java @@ -0,0 +1,46 @@ +package me.day05.practice; + +import java.util.Arrays; + +import me.day05.practice.exception.DuplicateUserException; + +public class Users { + private static final int DEFAULT_CAPACITY = 20; + private static Users users; + private User[] userList; + + private Users() { + userList = new User[DEFAULT_CAPACITY]; + } + + public static Users getInstance() { + if (users == null) { + Users.users = new Users(); + } + return Users.users; + } + + public User findByUserId(String userId) { + return Arrays.stream(this.userList) + .filter((user -> user.getUserId().equals(userId))) + .findFirst() + .orElse(null); + } + + public User copy(User user) throws CloneNotSupportedException { + return (User)(user.clone()); + } + + public User[] getUserList() { + return userList; + } + + public void setUserList(User[] userList) { + this.userList = userList; + } + + private boolean isDuplicateUser(User user) { + return Arrays.stream(this.userList) + .anyMatch(users -> users.getUserId().equals(user.getUserId())); + } +}