-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: balance game type을 enum으로 변경한다
- Loading branch information
Showing
2 changed files
with
36 additions
and
4 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/java/net/teumteum/user/domain/BalanceGameType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package net.teumteum.user.domain; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.function.BiFunction; | ||
import net.teumteum.user.domain.response.InterestQuestionResponse; | ||
|
||
public enum BalanceGameType { | ||
|
||
BALANCE("balance", (users, interestQuestion) -> interestQuestion.getBalanceGame(users)), | ||
STORY("story", (users, interestQuestion) -> interestQuestion.getStoryGame(users)), | ||
; | ||
|
||
private final String value; | ||
private final BiFunction<List<User>, InterestQuestion, InterestQuestionResponse> behavior; | ||
|
||
BalanceGameType(String value, BiFunction<List<User>, InterestQuestion, InterestQuestionResponse> behavior) { | ||
this.value = value; | ||
this.behavior = behavior; | ||
} | ||
|
||
public static BalanceGameType of(String value) { | ||
return Arrays.stream(BalanceGameType.values()) | ||
.filter(type -> type.value.equals(value)) | ||
.findAny() | ||
.orElseThrow( | ||
() -> new IllegalArgumentException("\"" + value + "\" 에 해당하는 enum값을 찾을 수 없습니다.") | ||
); | ||
} | ||
|
||
public InterestQuestionResponse getInterestQuestionResponse(List<User> users, InterestQuestion interestQuestion) { | ||
return behavior.apply(users, interestQuestion); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters