Skip to content

Commit

Permalink
refactor: enum equals 로직 개선 (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook02 authored Sep 13, 2024
1 parent 15be25e commit bdd647b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void validateStatusUpdatable() {
* 준회원 승급 가능 여부를 검증합니다.
*/
private void validateAssociateAvailable() {
if (role.equals(ASSOCIATE)) {
if (isAssociate()) {
throw new CustomException(MEMBER_ALREADY_ASSOCIATE);
}

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ public void validatePeriodNotStarted() {
}

public boolean isFirstRound() {
return roundType.equals(RoundType.FIRST);
return roundType == RoundType.FIRST;
}
}
Original file line number Diff line number Diff line change
@@ -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.*;

Expand Down Expand Up @@ -67,7 +66,7 @@ private void validatePeriodOverlap(
// 학년도, 학기, 모집회차가 모두 같은 경우
private void validateRoundOverlap(List<RecruitmentRound> 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);
Expand All @@ -76,14 +75,14 @@ private void validateRoundOverlap(List<RecruitmentRound> recruitmentRounds, Roun

// 1차 모집이 없는데 2차 모집을 생성하려고 하는 경우
private void validateRoundOneExist(List<RecruitmentRound> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit bdd647b

Please sign in to comment.