Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 기능 구현 체크리스트

## 구현 기능

### 입력 부분

- [ ] 기능 선택
- [ ] 1, 2, 3, Q 아닌 입력 값은 예외 처리

### 예외 처리

- [ ] 예외 처리 시 IllegalArgumentException를 발생
- [ ] [ERROR]로 시작하는 에러 메시지 출력
- [ ] 에러 메시지 출력 후 해당 부분부터 재입력 받기

### 출력 부분

- [ ] 기능 선택 출력
- [ ] 페어 매칭 출력
- [ ] 페어 매칭 결과 출력

### 페어 정보

- [ ] 크루 목록이 담긴 파일 리스트에 저장
- [ ] 미션 목록 리스트 저장
- [ ] 페어 정보 관리

### 페어 매칭

- [ ] 크루 목록 셔플
- [ ] 순서대로 두명씩 페어 매칭
- [ ] 총 인원이 홀수인 경우 마지막 페어에 포함
- [ ] 같은 레벨에서 페어 만난 경험이 있는 경우 셔플 후 재매칭
- [ ] 3회 시도까지 매칭이 되지 않거나 매칭을 할 수 있는 경우의 수가 없으면 에러 메시지를 출력

### 페어 조회

- [ ] 매칭 이력 없은 경우 에러 메시지 출력
- [ ] 매칭 이력이 있는 경우 목록 출력

### 페어 초기화

- [ ] 페어 목록 초기화
- [ ] 초기화 메시지 출력
4 changes: 4 additions & 0 deletions src/main/java/pairmatching/Application.java
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 src/main/java/pairmatching/controller/MatchingController.java
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())) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분을 메서드로 만들면 더 깔끔할거 같아요! ex) OptionCommand.isQuit()

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;

Choose a reason for hiding this comment

The 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();
}
}
14 changes: 14 additions & 0 deletions src/main/java/pairmatching/domain/Crew.java
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;
}
}
59 changes: 59 additions & 0 deletions src/main/java/pairmatching/domain/MatchingConditions.java
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);
}
}
68 changes: 68 additions & 0 deletions src/main/java/pairmatching/domain/MatchingRepository.java
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<>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clear() 를 함으로써 메모리 낭비를 줄이시는건 어떠실까요!

}
}
29 changes: 29 additions & 0 deletions src/main/java/pairmatching/domain/Pair.java
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);
}
}
28 changes: 28 additions & 0 deletions src/main/java/pairmatching/domain/Pairs.java
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);
}
}
28 changes: 28 additions & 0 deletions src/main/java/pairmatching/domain/constant/Course.java
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;
}
}
Loading