Skip to content

Commit

Permalink
refactor: HobbyName 검증 메서드 분할
Browse files Browse the repository at this point in the history
- 검증 방식에 따른 세부 메서드 분할
  • Loading branch information
devholic22 committed Feb 23, 2024
1 parent d1a4d0c commit e0370d7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/com/atwoz/member/domain/info/hobby/HobbyName.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,34 @@ public enum HobbyName {
}

public static List<HobbyName> findAllByNames(final List<String> names) {
validateSize(names);
validateNames(names);
return names.stream()
.map(HobbyName::from)
.toList();
}

public static void validateSize(final List<String> names) {
private static void validateNames(final List<String> names) {
validateIsNotEmptyNames(names);
validateIsUniqueNames(names);
validateIsNotOverMaxSizeOfHobby(names);
}

private static void validateIsNotEmptyNames(final List<String> names) {
if (names.isEmpty()) {
throw new HobbySizeException();
}
}

private static void validateIsUniqueNames(final List<String> names) {
Set<String> uniqueNames = new HashSet<>(names);
if (uniqueNames.size() != names.size()) {
throw new HobbyDuplicateException();
}
}

private static void validateIsNotOverMaxSizeOfHobby(final List<String> names) {
int validSize = Arrays.stream(values())
.filter(hobbyName -> uniqueNames.contains(hobbyName.getName()))
.filter(hobbyName -> names.contains(hobbyName.getName()))
.toList()
.size();
if (validSize > MAX_SIZE) {
Expand Down

0 comments on commit e0370d7

Please sign in to comment.