From bdd647beebce882bcdc309723a71777a9289948a Mon Sep 17 00:00:00 2001 From: Cho Sangwook <82208159+Sangwook02@users.noreply.github.com> Date: Fri, 13 Sep 2024 13:35:04 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20enum=20equals=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EA=B0=9C=EC=84=A0=20(#772)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/discord/domain/DiscordValidator.java | 2 +- .../gdsc/domain/member/domain/Member.java | 16 ++++++++-------- .../gdsc/domain/member/domain/MemberStatus.java | 4 ++-- .../recruitment/domain/RecruitmentRound.java | 2 +- .../domain/RecruitmentRoundValidator.java | 7 +++---- .../domain/recruitment/domain/RoundType.java | 8 ++++++++ 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/gdschongik/gdsc/domain/discord/domain/DiscordValidator.java b/src/main/java/com/gdschongik/gdsc/domain/discord/domain/DiscordValidator.java index c8d376a3b..10b6d5c09 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/discord/domain/DiscordValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/discord/domain/DiscordValidator.java @@ -32,7 +32,7 @@ public void validateVerifyDiscordCode( } public void validateAdminPermission(Member currentMember) { - if (!currentMember.getManageRole().equals(MemberManageRole.ADMIN)) { + if (currentMember.getManageRole() != MemberManageRole.ADMIN) { throw new CustomException(INVALID_ROLE); } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java b/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java index e2c07099b..44e684078 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java +++ b/src/main/java/com/gdschongik/gdsc/domain/member/domain/Member.java @@ -137,7 +137,7 @@ private void validateStatusUpdatable() { * 준회원 승급 가능 여부를 검증합니다. */ private void validateAssociateAvailable() { - if (role.equals(ASSOCIATE)) { + if (isAssociate()) { throw new CustomException(MEMBER_ALREADY_ASSOCIATE); } @@ -152,7 +152,7 @@ private void validateRegularAvailable() { throw new CustomException(MEMBER_ALREADY_REGULAR); } - if (!role.equals(ASSOCIATE)) { + if (!isAssociate()) { throw new CustomException(MEMBER_NOT_ASSOCIATE); } } @@ -335,26 +335,26 @@ public void updateMemberInfo( // 데이터 전달 로직 public boolean isGuest() { - return role.equals(GUEST); + return role == GUEST; } public boolean isAssociate() { - return role.equals(ASSOCIATE); + return role == ASSOCIATE; } public boolean isRegular() { - return role.equals(REGULAR); + return role == REGULAR; } public boolean isAdmin() { - return manageRole.equals(ADMIN); + return manageRole == ADMIN; } public boolean isMentor() { - return studyRole.equals(MENTOR); + return studyRole == MENTOR; } public boolean isStudent() { - return studyRole.equals(STUDENT); + return studyRole == STUDENT; } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/member/domain/MemberStatus.java b/src/main/java/com/gdschongik/gdsc/domain/member/domain/MemberStatus.java index a37e655eb..0864c3602 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/member/domain/MemberStatus.java +++ b/src/main/java/com/gdschongik/gdsc/domain/member/domain/MemberStatus.java @@ -13,10 +13,10 @@ public enum MemberStatus { private final String value; public boolean isDeleted() { - return this.equals(DELETED); + return this == DELETED; } public boolean isForbidden() { - return this.equals(FORBIDDEN); + return this == FORBIDDEN; } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RecruitmentRound.java b/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RecruitmentRound.java index 18d3cec87..94e6e1cd7 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RecruitmentRound.java +++ b/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RecruitmentRound.java @@ -94,6 +94,6 @@ public void validatePeriodNotStarted() { } public boolean isFirstRound() { - return roundType.equals(RoundType.FIRST); + return roundType == RoundType.FIRST; } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RecruitmentRoundValidator.java b/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RecruitmentRoundValidator.java index 42d4ec58a..e23d31589 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RecruitmentRoundValidator.java +++ b/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RecruitmentRoundValidator.java @@ -1,6 +1,5 @@ package com.gdschongik.gdsc.domain.recruitment.domain; -import static com.gdschongik.gdsc.domain.recruitment.domain.RoundType.*; import static com.gdschongik.gdsc.global.common.constant.TemporalConstant.*; import static com.gdschongik.gdsc.global.exception.ErrorCode.*; @@ -67,7 +66,7 @@ private void validatePeriodOverlap( // 학년도, 학기, 모집회차가 모두 같은 경우 private void validateRoundOverlap(List recruitmentRounds, RoundType roundType) { recruitmentRounds.stream() - .filter(recruitmentRound -> recruitmentRound.getRoundType().equals(roundType)) + .filter(recruitmentRound -> recruitmentRound.getRoundType() == roundType) .findAny() .ifPresent(ignored -> { throw new CustomException(RECRUITMENT_ROUND_TYPE_OVERLAP); @@ -76,14 +75,14 @@ private void validateRoundOverlap(List recruitmentRounds, Roun // 1차 모집이 없는데 2차 모집을 생성하려고 하는 경우 private void validateRoundOneExist(List recruitmentRounds, RoundType roundType) { - if (roundType.equals(SECOND) && recruitmentRounds.stream().noneMatch(RecruitmentRound::isFirstRound)) { + if (roundType.isSecond() && recruitmentRounds.stream().noneMatch(RecruitmentRound::isFirstRound)) { throw new CustomException(ROUND_ONE_DOES_NOT_EXIST); } } // 1차 모집을 비워둬서는 안되므로, 1차 모집을 2차 모집으로 수정하려고 하는 경우 예외 발생 private void validateRoundOneToTwo(RoundType previousRoundType, RoundType newRoundType) { - if (previousRoundType.equals(FIRST) && newRoundType.equals(SECOND)) { + if (previousRoundType.isFirst() && newRoundType.isSecond()) { throw new CustomException(ROUND_ONE_DOES_NOT_EXIST); } } diff --git a/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RoundType.java b/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RoundType.java index a70e8a963..f1d377d10 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RoundType.java +++ b/src/main/java/com/gdschongik/gdsc/domain/recruitment/domain/RoundType.java @@ -10,4 +10,12 @@ public enum RoundType { SECOND("2차"); private final String value; + + public boolean isFirst() { + return this == FIRST; + } + + public boolean isSecond() { + return this == SECOND; + } }