-
Notifications
You must be signed in to change notification settings - Fork 461
[페어 매칭] #165
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
Open
ChiwooKim
wants to merge
16
commits into
woowacourse:main
Choose a base branch
from
ChiwooKim:ChiwooKim
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
[페어 매칭] #165
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b3bdbe7
docs(README): 기능 구현 리스트 작성
ChiwooKim 95e141b
feat(OptionCommand): 기능 입력
ChiwooKim 04a4952
feat(OptionCommand): getter 추가
ChiwooKim 8ef7c6f
feat(InputView): 기능 입력 메소드 작성
ChiwooKim d0751de
feat(ExceptionMessage): 예외 처리 메시지 관리
ChiwooKim 1d72bac
feat(MatchinController): 컨트롤러 생성
ChiwooKim 28ac6e3
feat(Mission): 미션 관리
ChiwooKim 84dfa0c
feat(InputView): 정보 입력 메소드 작성
ChiwooKim 04d310a
리셋
ChiwooKim 97242d1
같은 레벨에서 페어 만난 경험, 3회 매칭 제외 구현
ChiwooKim fadf15c
feat(MatchingConditions): equals 오버라이드
ChiwooKim 77e9215
feat(MatchingRepository): 메소드 수정
ChiwooKim 55a11a9
feat(MatchingRepository): 페어 존재여부 메소드 작성
ChiwooKim b02fa55
feat(Pair): 페어 존재 여부 메소드 작성
ChiwooKim 64e44d6
feat(MatchingService): 매칭 로직 수정
ChiwooKim 60b0115
rename: 패키지 이동 및 경로 수정
ChiwooKim 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 hidden or 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,44 @@ | ||
| # 기능 구현 체크리스트 | ||
|
|
||
| ## 구현 기능 | ||
|
|
||
| ### 입력 부분 | ||
|
|
||
| - [ ] 기능 선택 | ||
| - [ ] 1, 2, 3, Q 아닌 입력 값은 예외 처리 | ||
|
|
||
| ### 예외 처리 | ||
|
|
||
| - [ ] 예외 처리 시 IllegalArgumentException를 발생 | ||
| - [ ] [ERROR]로 시작하는 에러 메시지 출력 | ||
| - [ ] 에러 메시지 출력 후 해당 부분부터 재입력 받기 | ||
|
|
||
| ### 출력 부분 | ||
|
|
||
| - [ ] 기능 선택 출력 | ||
| - [ ] 페어 매칭 출력 | ||
| - [ ] 페어 매칭 결과 출력 | ||
|
|
||
| ### 페어 정보 | ||
|
|
||
| - [ ] 크루 목록이 담긴 파일 리스트에 저장 | ||
| - [ ] 미션 목록 리스트 저장 | ||
| - [ ] 페어 정보 관리 | ||
|
|
||
| ### 페어 매칭 | ||
|
|
||
| - [ ] 크루 목록 셔플 | ||
| - [ ] 순서대로 두명씩 페어 매칭 | ||
| - [ ] 총 인원이 홀수인 경우 마지막 페어에 포함 | ||
| - [ ] 같은 레벨에서 페어 만난 경험이 있는 경우 셔플 후 재매칭 | ||
| - [ ] 3회 시도까지 매칭이 되지 않거나 매칭을 할 수 있는 경우의 수가 없으면 에러 메시지를 출력 | ||
|
|
||
| ### 페어 조회 | ||
|
|
||
| - [ ] 매칭 이력 없은 경우 에러 메시지 출력 | ||
| - [ ] 매칭 이력이 있는 경우 목록 출력 | ||
|
|
||
| ### 페어 초기화 | ||
|
|
||
| - [ ] 페어 목록 초기화 | ||
| - [ ] 초기화 메시지 출력 |
This file contains hidden or 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,7 +1,11 @@ | ||
| package pairmatching; | ||
|
|
||
| import pairmatching.controller.MatchingController; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO 구현 진행 | ||
| MatchingController matchingController = new MatchingController(); | ||
| matchingController.run(); | ||
| } | ||
| } |
106 changes: 106 additions & 0 deletions
106
src/main/java/pairmatching/controller/MatchingController.java
This file contains hidden or 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,106 @@ | ||
| package pairmatching.controller; | ||
|
|
||
| import java.util.List; | ||
| import pairmatching.domain.MatchingConditions; | ||
| import pairmatching.domain.constant.OptionCommand; | ||
| import pairmatching.domain.Pairs; | ||
| import pairmatching.domain.constant.RematchingCommand; | ||
| import pairmatching.service.MatchingService; | ||
| import pairmatching.view.InputView; | ||
| import pairmatching.view.OutputView; | ||
|
|
||
| public class MatchingController { | ||
|
|
||
| private final InputView inputView; | ||
| private final OutputView outputView; | ||
| private final MatchingService matchingService; | ||
|
|
||
| public MatchingController() { | ||
| this.inputView = new InputView(); | ||
| this.outputView = new OutputView(); | ||
| this.matchingService = new MatchingService(); | ||
| } | ||
|
|
||
| public void run() { | ||
| start(); | ||
| } | ||
|
|
||
| private void start() { | ||
| while (true) { | ||
| String option = readOption(); | ||
| if (option.equals(OptionCommand.MATCHING.getCommand())) { | ||
| match(); | ||
| } | ||
| if (option.equals(OptionCommand.CHECK.getCommand())) { | ||
| check(); | ||
| } | ||
| if (option.equals(OptionCommand.RESET.getCommand())) { | ||
| reset(); | ||
| } | ||
| if (option.equals(OptionCommand.QUIT.getCommand())) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private String readOption() { | ||
| outputView.printSelectOption(); | ||
| while (true) { | ||
| try { | ||
| return inputView.readOption(); | ||
| } catch (IllegalArgumentException e) { | ||
| outputView.printException(e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void match() { | ||
| MatchingConditions matchingConditions; | ||
| while (true) { | ||
| matchingConditions = readConditions(); | ||
| if (matchingService.hasConditions(matchingConditions)) { | ||
| break; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분에서 이미 매칭이 있어 break가 되면 반복문을 벗어나게 되어서 아래 리매칭을 묻는 부분이 진행이 안되지 않나요??? |
||
| } | ||
| outputView.printRematching(); | ||
| RematchingCommand rematching = RematchingCommand.from(inputView.readRematching()); | ||
| if (rematching == RematchingCommand.REMATCHING) { | ||
| break; | ||
| } | ||
| } | ||
| Pairs pairs = matchingService.matchPair(matchingConditions); | ||
| outputView.printPairs(pairs); | ||
| } | ||
|
|
||
| private MatchingConditions readConditions() { | ||
| outputView.printSelectCondition(); | ||
| while (true) { | ||
| try { | ||
| List<String> conditions = inputView.readConditions(); | ||
| return new MatchingConditions(conditions); | ||
| } catch (IllegalArgumentException e) { | ||
| outputView.printException(e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void check() { | ||
| Pairs pairs = checkPairs(); | ||
| outputView.printPairs(pairs); | ||
| } | ||
|
|
||
| private Pairs checkPairs() { | ||
| while (true) { | ||
| try { | ||
| MatchingConditions matchingConditions = readConditions(); | ||
| return matchingService.findPairs(matchingConditions); | ||
| } catch (IllegalArgumentException e) { | ||
| outputView.printException(e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void reset() { | ||
| matchingService.resetData(); | ||
| outputView.printReset(); | ||
| } | ||
| } | ||
This file contains hidden or 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,14 @@ | ||
| package pairmatching.domain; | ||
|
|
||
| public class Crew { | ||
|
|
||
| private final String name; | ||
|
|
||
| public Crew(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
| } |
This file contains hidden or 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,59 @@ | ||
| package pairmatching.domain; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import pairmatching.domain.constant.Course; | ||
| import pairmatching.domain.constant.Level; | ||
| import pairmatching.domain.constant.Mission; | ||
| import pairmatching.exception.ExceptionMessage; | ||
|
|
||
| public class MatchingConditions { | ||
|
|
||
| private static final int INPUT_SIZE = 3; | ||
| private final Course course; | ||
| private final Level level; | ||
| private final Mission mission; | ||
|
|
||
| public MatchingConditions(List<String> conditions) { | ||
| validateSize(conditions); | ||
| this.course = Course.from(conditions.get(0)); | ||
| this.level = Level.from(conditions.get(1)); | ||
| this.mission = Mission.from(conditions.get(2)); | ||
| } | ||
|
|
||
| private void validateSize(List<String> conditions) { | ||
| if (conditions.size() != INPUT_SIZE) { | ||
| throw new IllegalArgumentException( | ||
| ExceptionMessage.INVALID_MATCHING_CONDITIONS.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public Course getCourse() { | ||
| return course; | ||
| } | ||
|
|
||
| public Level getLevel() { | ||
| return level; | ||
| } | ||
|
|
||
| public Mission getMission() { | ||
| return mission; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (!(o instanceof MatchingConditions)) { | ||
| return false; | ||
| } | ||
| MatchingConditions conditions = (MatchingConditions) o; | ||
| return course == conditions.course && level == conditions.level && mission == conditions.mission; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(course, level, mission); | ||
| } | ||
| } |
This file contains hidden or 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,68 @@ | ||
| package pairmatching.domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import pairmatching.exception.ExceptionMessage; | ||
|
|
||
| public class MatchingRepository { | ||
|
|
||
| private List<Pairs> matchingRepository; | ||
|
|
||
| public MatchingRepository() { | ||
| this.matchingRepository = new ArrayList<>(); | ||
| } | ||
|
|
||
| public void add(Pairs pairs) { | ||
| matchingRepository.add(pairs); | ||
| } | ||
|
|
||
| public boolean hasPairs(MatchingConditions conditions, Pairs makePairs) { | ||
| List<Pairs> sameLevelPairs = matchingRepository.stream() | ||
| .filter(pairs -> pairs.getMatchingConditions().getLevel() == conditions.getLevel()) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| for (Pairs sameLevel : sameLevelPairs) { | ||
| if (checkPair(makePairs, sameLevel)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private boolean checkPair(Pairs makePairs, Pairs sameLevel) { | ||
| for (Pair pair : sameLevel.getPairs()) { | ||
| if (hasPair(makePairs, pair)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private boolean hasPair(Pairs makePairs, Pair pair) { | ||
| for (Pair makePair : makePairs.getPairs()) { | ||
| boolean result = pair.isCrews(makePair); | ||
| if (result) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public Pairs search(MatchingConditions conditions) { | ||
| return matchingRepository.stream() | ||
| .filter(pairs -> pairs.getMatchingConditions().equals(conditions)) | ||
| .findAny() | ||
| .orElseThrow(() -> new IllegalArgumentException( | ||
| ExceptionMessage.NON_EXISTENT_HISTORY.getMessage())); | ||
| } | ||
|
|
||
| public boolean hasConditionsPair(MatchingConditions conditions) { | ||
| return matchingRepository.stream() | ||
| .noneMatch(pairs -> pairs.getMatchingConditions().equals(conditions)); | ||
| } | ||
|
|
||
| public void reset() { | ||
| matchingRepository = new ArrayList<>(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. clear() 를 함으로써 메모리 낭비를 줄이시는건 어떠실까요! |
||
| } | ||
| } | ||
This file contains hidden or 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,29 @@ | ||
| package pairmatching.domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class Pair { | ||
|
|
||
| private static final int DUPLICATION_NUMBER = 1; | ||
| private final List<Crew> crews; | ||
|
|
||
| public Pair() { | ||
| this.crews = new ArrayList<>(); | ||
| } | ||
|
|
||
| public void add(Crew crew) { | ||
| crews.add(crew); | ||
| } | ||
|
|
||
| public boolean isCrews(Pair pair) { | ||
| return pair.getCrews().stream() | ||
| .filter(this.crews::contains) | ||
| .count() > DUPLICATION_NUMBER; | ||
| } | ||
|
|
||
| public List<Crew> getCrews() { | ||
| return Collections.unmodifiableList(crews); | ||
| } | ||
| } |
This file contains hidden or 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,28 @@ | ||
| package pairmatching.domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class Pairs { | ||
|
|
||
| private final MatchingConditions matchingConditions; | ||
| private final List<Pair> pairs; | ||
|
|
||
| public Pairs(MatchingConditions matchingConditions) { | ||
| this.matchingConditions = matchingConditions; | ||
| this.pairs = new ArrayList<>(); | ||
| } | ||
|
|
||
| public void add(Pair pair) { | ||
| pairs.add(pair); | ||
| } | ||
|
|
||
| public MatchingConditions getMatchingConditions() { | ||
| return matchingConditions; | ||
| } | ||
|
|
||
| public List<Pair> getPairs() { | ||
| return Collections.unmodifiableList(pairs); | ||
| } | ||
| } |
This file contains hidden or 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,28 @@ | ||
| package pairmatching.domain.constant; | ||
|
|
||
| import java.util.Arrays; | ||
| import pairmatching.exception.ExceptionMessage; | ||
|
|
||
| public enum Course { | ||
| BACKEND("백엔드"), | ||
| FRONTEND("프론트엔드"); | ||
|
|
||
| private String name; | ||
|
|
||
| Course(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| public static Course from(String input) { | ||
| return Arrays.stream(Course.values()) | ||
| .filter(course -> course.name.equals(input)) | ||
| .findAny() | ||
| .orElseThrow( | ||
| () -> new IllegalArgumentException( | ||
| ExceptionMessage.INVALID_MATCHING_CONDITIONS.getMessage())); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
| } |
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.
이부분을 메서드로 만들면 더 깔끔할거 같아요! ex) OptionCommand.isQuit()