-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Review #1916
Open
slay1379
wants to merge
78
commits into
woowacourse-precourse:main
Choose a base branch
from
slay1379:hi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Code Review #1916
Changes from all commits
Commits
Show all changes
78 commits
Select commit
Hold shift + click to select a range
513b727
Update README.md
slay1379 bacfd04
[feat]: 문자열 입력 기능 구현
slay1379 a8871e1
Merge branch 'main' of https://github.com/slay1379/java-calculator-7
slay1379 3a66279
[feat]: 계산기 엔티티 생성
slay1379 2955897
[feat]: Calculator 엔티티에 구분자 추가 기능 구현
slay1379 9eae8f1
[feat]: 계산기 엔티티에 숫자 추가 메소드 구현
slay1379 65e1541
[feat]: 계산기 엔티티 구분자 반환 메소드 구현
slay1379 7ac7534
[feat]: 계산기 엔티티 숫자 리스트 반환 메소드 구현
slay1379 d72d8c6
[feat]: 구분자 커스텀 구분하는 메소드 구현
slay1379 91a82e0
[feat]: 계산기 모든 숫자 더하는 메소드 구현
slay1379 d0efb04
[feat]: 결과 출력 기능 구현
slay1379 4d795d9
[feat]: 컨트롤러 기능 구현
slay1379 dfa499f
[refactor]: 생성자 없어서 오류 나는 부분 리팩토링
slay1379 27607b6
[rafactor]: 예외처리 로직 코드 시스템 종료하도록 리팩토링
slay1379 2bcf2ea
[refactor]: 커스텀 구분자 예외처리 조건 추가
slay1379 21afeba
[refactor]: 구분자 조건문 수정
slay1379 e3b97f4
[refactor]: 문자열이 숫자인지 구분하는 메소드 구현
slay1379 1af8196
[docs]: 구현해야 할 기능 목록 추가
slay1379 d541208
[refactor]: 잘못된 입력 검사 로직 메소드로 구현
slay1379 8fa22cd
[refactor]: 구분자 추출 로직 메소드로 구현
slay1379 560de3f
[refactor]: 구분자인지 구분하는 로직 메소드로 구현
slay1379 90a1a4a
[feat]: 커스텀 구분자 메소드 테스트 기능 구현
slay1379 a3e310d
[refactor]: 잘못된 입력 메소드 조건 분리 리팩토링
slay1379 fa305ed
[feat]: 구분자 추출하는 테스트 메소드 구현
slay1379 711a0e0
[feat]: divideSeparator 메소드 음수 구분 로직 구현
slay1379 30d730e
[refator]: 음수 처리 로직 삭제
slay1379 dcd707c
[refactor]: 커스텀 구분자 추출하는 메소드 수정
slay1379 29cbbbe
[refactor]: 생성자 주입 코드 리팩토링
slay1379 8fd2115
[refactor]: 문자열 구분자를 기준으로 구분하는 로직 수정
slay1379 418b3a4
[docs]: 생각해봐야 할 것 추가
slay1379 d1164b8
[refactor]: 문자열 구분자를 기준으로 구분하는 로직 수정
slay1379 d28dadf
[refactor]: 문자열 구분자를 기준으로 구분하는 로직 수정
slay1379 13c4863
[refactor]: 커스텀구분자 정규식으로 코드 리팩토링
slay1379 e31a7e0
[refactor]: 구분자 구분하는 로직 수정
slay1379 1336d82
[feat]: test 코드 작성
slay1379 36ed8c2
전체 푸쉬
slay1379 bdab76b
refactor(): 추천메뉴를 못먹는메뉴에 추가하던 로직 수정
slay1379 4cf7998
feat(inedible): 못 먹는 메뉴가 실제 메뉴인지 검증하는 기능 추가
slay1379 dab2848
feat(Coach): 코치 객체 생성
slay1379 a8d33b1
feat(Exception): 오류 메세지 관리하는 클래스 생성
slay1379 f5c568c
feat(Coach): 코치 이름 길이 검증하는 기능 추가
slay1379 f748023
feat(InputView): 코치 이름 입력받는 기능 추가
slay1379 4443095
feat(InputView): 못먹는 메뉴 입력받는 기능 추가
slay1379 6839f41
feat(Exception): 코치 수 오류 메세지 추가
slay1379 98fb823
feat(Coachs): 코치 수 검증하는 기능 추가
slay1379 68d6133
feat(InedibleMenu): 못먹는 메뉴 객체 생성 및 개수 검증기능 추가
slay1379 670f786
feat(Exception): 추천 메뉴 중복 에러메세지 추가
slay1379 a43a353
feat(RecommendMenu): 추천메뉴 중복 검증하는 기능 추가
slay1379 4499059
feat(RecommendMenu): 추천메뉴 추가하는 기능 추가
slay1379 7cf8f46
refactor(Coach): 자료구조 수정
slay1379 932c7e5
feat(Menu): 랜덤으로 카테고리 선정하는 기능 추가
slay1379 d15aa50
feat(Menu): 랜덤으로 메뉴 추천하는 기능 추가
slay1379 6e53252
feat(Menu): 입력한 메뉴가 실제 메뉴에 있는지 확인하는 기능 추가
slay1379 6a58b65
feat(Exception): 존재하지 않는 메뉴 오류메세지 추가
slay1379 6f8a72d
feat(InedibleMenu): 입력 받은 못 먹는 메뉴가 실제 메뉴인지 검증하는 기능 추가
slay1379 f70356f
feat(InedibleMenu): 입력 받은 못 먹는 메뉴가 실제 메뉴인지 검증하는 기능 추가
slay1379 ef51dec
fix(RecommendMenu): 메소드 오타 수정
slay1379 a956788
feat(Categories): 카테고리 객체 생성 및 카테고리 추가 기능 추가
slay1379 9f47ef8
feat(Exception): 카테고리 추천 횟수 넘어갔을 때 오류메세지 추가
slay1379 27f289f
feat(Categories): 카테고리 추천 2회 이상인지 검증하는 기능 추가
slay1379 f4e3318
feat(InedibleMenu): 못 먹는 메뉴가 0개일때 경우 추가
slay1379 a3bcb0b
feat(Recommendation): 카테고리 추가 기능 추가
slay1379 f2b59f6
feat(Coach): 추천메뉴 추가 기능 추가
slay1379 c54eaed
feat(Coachs): 코치마다 추천메뉴 한 사이클 추가 기능 추가
slay1379 9599abd
refactor(Menu): 랜덤으로 카테고리 선정 기능 따로 분리
slay1379 72acbca
refactor(Coachs): 랜덤으로 카테고리 선정 기능 따로 분리
slay1379 59d8a96
refactor(Coachs): 랜덤으로 카테고리 선정 기능 따로 분리
slay1379 f8d3c75
feat(Recommendation): 카테고리 추가, 추천메뉴 추가 기능 추가
slay1379 eabf2b4
feat(Categories): 현재까지 추천된 카테고리의 수가 5개인지의 여부를 반환하는 기능 추가
slay1379 6d86583
feat(Recommendation): 추천이 끝났는지 여부를 반환하는 기능 추가
slay1379 2f73cc5
feat(RecommendationService): 한 사이클 추천 기능, 카테고리 랜덤 선정, 모든 추천사이클 순환 기능 추가
slay1379 068fda3
feat(OutputView): 시작 메세지 출력 기능 추가
slay1379 c85bccb
feat(OutputView): 메뉴 추천 결과 출력 기능 추가
slay1379 5506941
feat(Categories): 카테고리 반환 기능 추가
slay1379 647fc1e
feat(Categories): 카테고리 반환 기능 추가
slay1379 c365732
feat(): 코치 반환 기능 추가
slay1379 9b8a075
feat(): 반환기능들 추가
slay1379 d76546f
refactor(): 예외처리 수정
slay1379 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1,17 @@ | ||
# java-calculator-precourse | ||
# java-calculator-precourse | ||
|
||
구현 할 기능 목록 | ||
1. 문자열을 입력받는 기능 | ||
2. 문자열을 구분자를 기준으로 분리하는 기능 | ||
3. 커스텀 구분자를 지정하는 기능 | ||
4. 잘못된 값을 입력할 경우 예외처리하는 기능 | ||
5. 숫자를 더하는 기능 | ||
6. 결과를 출력하는 기능 | ||
|
||
|
||
초기 구현 후 리팩토링 할 목록 | ||
1. 문자열을 구분자를 기준으로 분리하는 기능 -> 기능들을 더 메소드 단위로 나누기 | ||
|
||
|
||
예외처리 | ||
1. 잘못된 입력 | ||
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
plugins { | ||
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' | ||
} | ||
rootProject.name = 'java-calculator' | ||
rootProject.name = 'java-menu' |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
package menu; | ||
|
||
import menu.controller.RecommendationController; | ||
import menu.view.InputView; | ||
import menu.view.OutputView; | ||
|
||
public class Application { | ||
public static void main(String[] args) { | ||
InputView inputView = new InputView(); | ||
OutputView outputView = new OutputView(); | ||
RecommendationController recommendationController = new RecommendationController(inputView, outputView); | ||
|
||
recommendationController.run(); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/menu/controller/RecommendationController.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,70 @@ | ||
package menu.controller; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import menu.domain.Categories; | ||
import menu.domain.Coach; | ||
import menu.domain.Coachs; | ||
import menu.domain.InedibleMenu; | ||
import menu.domain.RecommendMenu; | ||
import menu.domain.Recommendation; | ||
import menu.service.RecommendationService; | ||
import menu.view.InputView; | ||
import menu.view.OutputView; | ||
|
||
public class RecommendationController { | ||
private final InputView inputView; | ||
private final OutputView outputView; | ||
private RecommendationService recommendationService; | ||
private Recommendation recommendation; | ||
|
||
public RecommendationController(InputView inputView, | ||
OutputView outputView) { | ||
this.inputView = inputView; | ||
this.outputView = outputView; | ||
} | ||
|
||
public void run() { | ||
outputView.printStart(); | ||
Coachs coachs = createCoachs(); | ||
for (Coach coach : coachs.getCoachs()) { | ||
createInedible(coach); | ||
} | ||
Categories categories = new Categories(); | ||
recommendation = new Recommendation(coachs, categories); | ||
recommendationService = new RecommendationService(recommendation); | ||
recommendationService.recommendationMenu(); | ||
outputView.printResult(recommendation.getCategories().getCategories(), | ||
recommendation.getCoachs().getCoachs()); | ||
} | ||
|
||
private void createCoach(String coach, List<Coach> coaches) { | ||
InedibleMenu inedibleMenu = new InedibleMenu(); | ||
RecommendMenu recommendMenu = new RecommendMenu(); | ||
coaches.add(new Coach(coach, inedibleMenu, recommendMenu)); | ||
} | ||
|
||
private Coachs createCoachs() { | ||
try { | ||
List<Coach> coaches = new ArrayList<>(); | ||
List<String> inputCoachs = inputView.readCoachs(); | ||
for (String coach : inputCoachs) { | ||
createCoach(coach, coaches); | ||
} | ||
Coachs coachs = new Coachs(coaches); | ||
return coachs; | ||
} catch (IllegalArgumentException e) { | ||
System.out.println(e.getMessage()); | ||
return createCoachs(); | ||
} | ||
} | ||
|
||
private void createInedible(Coach coach) { | ||
try { | ||
coach.getInedibleMenu().setEdibleMenu(inputView.readInedibles(coach.getName())); | ||
} catch (IllegalArgumentException e) { | ||
System.out.println(e.getMessage()); | ||
createInedible(coach); | ||
} | ||
} | ||
} |
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,37 @@ | ||
package menu.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import menu.util.Exception; | ||
|
||
public class Categories { | ||
private List<String> categories = new ArrayList<>(); | ||
|
||
public Categories() { | ||
} | ||
|
||
public void addCategory(String category) { | ||
validateCategory(category); | ||
categories.add(category); | ||
} | ||
|
||
public boolean isComplete() { | ||
if (categories.size() == 5) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public List<String> getCategories() { | ||
return categories; | ||
} | ||
|
||
private void validateCategory(String category) { | ||
long count = categories.stream() | ||
.filter(c -> c.equals(category)) | ||
.count(); | ||
if (count >= 2) { | ||
throw new IllegalArgumentException(Exception.ERROR + Exception.OVER_CATEGORY_AMOUNT); | ||
} | ||
} | ||
} |
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,38 @@ | ||
package menu.domain; | ||
|
||
import menu.util.Exception; | ||
|
||
public class Coach { | ||
private final String name; | ||
private InedibleMenu inedibleMenu; | ||
private RecommendMenu recommendMenu; | ||
|
||
public Coach(String name, InedibleMenu inedibleMenu, RecommendMenu recommendMenu) { | ||
validateNameLength(name); | ||
this.name = name; | ||
this.inedibleMenu = inedibleMenu; | ||
this.recommendMenu = recommendMenu; | ||
} | ||
|
||
public void addRecommendMenu(String menu) { | ||
recommendMenu.addRecommendMenu(menu); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public RecommendMenu getRecommendMenu() { | ||
return recommendMenu; | ||
} | ||
|
||
public InedibleMenu getInedibleMenu() { | ||
return inedibleMenu; | ||
} | ||
|
||
private void validateNameLength(String name) { | ||
if (name.length() < 2 || name.length() > 4) { | ||
throw new IllegalArgumentException(Exception.ERROR + Exception.COACH_NAME_LENGTH); | ||
} | ||
} | ||
} |
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,57 @@ | ||
package menu.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import menu.util.Exception; | ||
|
||
public class Coachs { | ||
private List<Coach> coachs; | ||
|
||
public Coachs(List<Coach> coachs) { | ||
validateCoachAmount(coachs); | ||
this.coachs = coachs; | ||
} | ||
|
||
public void recommendMenuOneCycle(String category) { | ||
for (Coach coach : coachs) { | ||
recommendMenu(coach, category); | ||
} | ||
} | ||
|
||
public List<String> getCoachNames() { | ||
List<String> coachNames = new ArrayList<>(); | ||
for (Coach coach : coachs) { | ||
coachNames.add(coach.getName()); | ||
} | ||
return coachNames; | ||
} | ||
|
||
public List<Coach> getCoachs() { | ||
return coachs; | ||
} | ||
|
||
private void recommendMenu(Coach coach, String category) { | ||
try { | ||
String menu = Menu.recommendationMenu(category); | ||
validateMenuIsInedible(coach, menu); | ||
coach.addRecommendMenu(menu); | ||
} catch (IllegalArgumentException e) { | ||
recommendMenu(coach, category); | ||
} | ||
} | ||
|
||
private void validateMenuIsInedible(Coach coach, String menu) { | ||
if (coach.getInedibleMenu().isEdibleMenu(menu)) { | ||
throw new IllegalArgumentException(Exception.ERROR); | ||
} | ||
} | ||
|
||
private void validateCoachAmount(List<Coach> coachs) { | ||
if (coachs.size() < 2) { | ||
throw new IllegalArgumentException(Exception.ERROR + Exception.COACH_AMOUNT_UNDER_RANGE); | ||
} | ||
if (coachs.size() > 5) { | ||
throw new IllegalArgumentException(Exception.ERROR + Exception.COACH_AMOUNT_OVER_RANGE); | ||
} | ||
} | ||
} |
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,41 @@ | ||
package menu.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import menu.util.Exception; | ||
|
||
public class InedibleMenu { | ||
private List<String> menus = new ArrayList<>(); | ||
|
||
public InedibleMenu() { | ||
} | ||
|
||
public boolean isEdibleMenu(String menu) { | ||
if (menus.contains(menu)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public void setEdibleMenu(List<String> menus) { | ||
if (!(menus.size() == 1 && menus.get(0).equals(""))) { | ||
validateMenuAmount(menus); | ||
validateInedibleMenu(menus); | ||
} | ||
this.menus = menus; | ||
} | ||
|
||
private void validateMenuAmount(List<String> menus) { | ||
if (menus.size() > 2) { | ||
throw new IllegalArgumentException(Exception.ERROR + Exception.INEDIBLE_MENU_AMOUNT_OVER_RANGE); | ||
} | ||
} | ||
|
||
private void validateInedibleMenu(List<String> menus) { | ||
for (String menu : menus) { | ||
if (!Menu.isInMenu(menu)) { | ||
throw new IllegalArgumentException(Exception.ERROR + Exception.NOT_EXIST_MENU); | ||
} | ||
} | ||
} | ||
} |
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,48 @@ | ||
package menu.domain; | ||
|
||
import camp.nextstep.edu.missionutils.Randoms; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public enum Menu { | ||
일식(1, List.of("규동", "우동", "미소시루", "스시", "가츠동", "오니기리", "하이라이스", "라멘", "오코노미야끼")), | ||
한식(2, List.of("김밥", "김치찌개", "쌈밥", "된장찌개", "비빔밥", "칼국수", "불고기", "떡볶이", "제육볶음")), | ||
중식(3, List.of("깐풍기", "볶음면", "동파육", "짜장면", "짬뽕", "마파두부", "탕수육", "토마토 달걀볶음", "고추잡채")), | ||
아시안(4, List.of("팟타이", "카오 팟", "나시고렝", "파인애플 볶음밥", "쌀국수", "똠얌꿍", "반미", "월남쌈", "분짜")), | ||
양식(5, List.of("라자냐", "그라탱", "뇨끼", "끼슈", "프렌치 토스트", "바게트", "스파게티", "피자", "파니니")); | ||
|
||
private int category; | ||
private List<String> menus; | ||
|
||
Menu(int category, List<String> menus) { | ||
this.category = category; | ||
this.menus = menus; | ||
} | ||
|
||
public static String recommendationMenu(String category) { | ||
return Randoms.shuffle(Menu.valueOf(category).menus).get(0); | ||
} | ||
|
||
public static boolean isInMenu(String inputMenu) { | ||
List<String> allMenu = new ArrayList<>(); | ||
for (Menu value : Menu.values()) { | ||
for (String menu : value.menus) { | ||
allMenu.add(menu); | ||
} | ||
} | ||
if (allMenu.contains(inputMenu)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public static String randomCategory() { | ||
int number = Randoms.pickNumberInRange(1, 5); | ||
for (Menu value : Menu.values()) { | ||
if (value.category == number) { | ||
return value.name(); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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,27 @@ | ||
package menu.domain; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import menu.util.Exception; | ||
|
||
public class RecommendMenu { | ||
private List<String> menus = new ArrayList<>(); | ||
|
||
public RecommendMenu() { | ||
} | ||
|
||
public void addRecommendMenu(String menu) { | ||
validateRecommendMenu(menu); | ||
menus.add(menu); | ||
} | ||
|
||
public List<String> getMenus() { | ||
return menus; | ||
} | ||
|
||
private void validateRecommendMenu(String menu) { | ||
if (menus.contains(menu)) { | ||
throw new IllegalArgumentException(Exception.ERROR + Exception.DUPLICATE_RECOMMEND_MENU); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README.md에 어떤 기능을 구현할 지 미리 정리해봅시다!