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
35 changes: 35 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 페어 매칭 프로그램

## 개발 기능 목록

- [ ] 출력 기능
- [ ] 기능 선택 안내 문구
- [ ] 과정, 미션, 레벨 선택 안내 문구
- [ ] 페어 매칭 결과
- [ ] 페어 재매칭 시도 문구
- [ ] 초기화 안내 문구

- [ ] 기능 선택 입력 기능
- [ ] 한 개의 문자로 입력되는지 검증

- [ ] 기능 선택 검증 기능
- [ ] 1, 2, 3, Q 문자 중 하나인지 검증

- [ ] 과정, 미션, 레벨 선택 입력 기능
- [ ] ", "으로 구분되고, 과정은 3 ~ 5 글자, 레벨은 3 글자, 미션은 2 ~ 6글자로 입력 되는지 검증

- [ ] 과정, 미션, 레벨 선택 검증 기능
- [ ] 정해진 과정, 미션, 레벨인지 검증

- [ ] 매칭 이력 확인 기능

- [ ] 페어 매칭 기능
- [ ] 3회 초과 시도 시 에러
- [ ] 동 레벨에서 중복 페어 금지
- [ ] 홀수인 경어 마지막 크루는 마지막 페어에 포함

- [ ] 페어 조회 기능
- [ ] 매칭 이력 없을 시 에러

- [ ] 페어 매칭 초기화 기능

78 changes: 78 additions & 0 deletions src/main/java/pairmatching/controller/PairMatchingController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package pairmatching.controller;

import pairmatching.domain.MatchingHistory;
import pairmatching.domain.MatchingMachine;
import pairmatching.domain.choice.Choice;
import pairmatching.domain.choice.ChoiceMaker;
import pairmatching.domain.choice.item.Course;
import pairmatching.domain.choice.item.Level;
import pairmatching.domain.choice.item.Mission;
import pairmatching.domain.command.UserCommand;
import pairmatching.domain.program.PairMatchingProgram;
import pairmatching.domain.command.Command;
import pairmatching.view.InputView;
import pairmatching.view.OutputView;

import java.util.List;
import java.util.function.Supplier;

public class PairMatchingController {

private final InputView inputView;
private final OutputView outputView;

public PairMatchingController(InputView inputView, OutputView outputView) {
this.inputView = inputView;
this.outputView = outputView;
}

public void runPairMatchingProgram() {
executeUserCommand();


}

private void executeUserCommand() {
PairMatchingProgram program = new PairMatchingProgram(new MatchingHistory(), new MatchingMachine());
UserCommand command = repeat(this::readUserCommand);
if (command.isCommandOf(Command.MATCHING)) {
Choice choice = repeat(this::readChoice);
if (program.hasMatched(choice)) {
outputView.printReMatchingGuide();
inputView.readReMatchingCommand();
}
}
if (command.isCommandOf(Command.CHECKING)) {

}
if (command.isCommandOf(Command.RESETTING)) {

}
if (command.isCommandOf(Command.QUITTING)) {

}
}

private Choice readChoice() {
ChoiceMaker choiceMaker = new ChoiceMaker();
outputView.printChoiceGuideMessage(Course.namesOfValues(), Level.namesOfValues(), Mission.values());
List<String> items = inputView.readChoice();
return choiceMaker.createChoice(items);
}

private UserCommand readUserCommand() {
outputView.printCommandGuideMessage(Command.values());
String command = inputView.readCommand();
return new UserCommand(command);
}

private <T> T repeat(Supplier<T> inputReader) {
while(true) {
try {
return inputReader.get();
} catch (IllegalArgumentException e) {
outputView.print(e.getMessage());
}
}
}
}
20 changes: 20 additions & 0 deletions src/main/java/pairmatching/domain/MatchingHistory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package pairmatching.domain;

import pairmatching.domain.choice.Choice;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MatchingHistory {

private final Map<Choice, Set<Crew>> history;

public MatchingHistory() {
this.history = new HashMap<Choice, Set<Crew>>();
}

public boolean hasMatchingOf(Choice choice) {
return history.containsKey(choice);
}
}
5 changes: 5 additions & 0 deletions src/main/java/pairmatching/domain/MatchingMachine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package pairmatching.domain;

public class MatchingMachine {

}
15 changes: 15 additions & 0 deletions src/main/java/pairmatching/domain/choice/Choice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package pairmatching.domain.choice;

import pairmatching.domain.choice.item.Course;
import pairmatching.domain.choice.item.Mission;

public class Choice {

private final Course course;
private final Mission mission;

public Choice(String courseName, String missionName) {
this.course = Course.valueOfCourse(courseName);
this.mission = Mission.valueOfMission(missionName);
}
}
40 changes: 40 additions & 0 deletions src/main/java/pairmatching/domain/choice/ChoiceMaker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package pairmatching.domain.choice;

import pairmatching.domain.choice.item.Course;
import pairmatching.domain.choice.item.Level;
import pairmatching.domain.choice.item.Mission;

import java.util.List;

public class ChoiceMaker {

public Choice createChoice(List<String> items) {
String courseName = items.get(0);
String levelName = items.get(1);
String missionName = items.get(2);
validate(courseName, levelName, missionName);

return new Choice(courseName, missionName);
}

private void validate(String courseName, String levelName, String missionName) {
if (!Course.contains(courseName)) {
throw new IllegalArgumentException("[ERROR] 해당하는 과정이 존재하지 않습니다.");
}
if (!Level.contains(levelName)) {
throw new IllegalArgumentException("[ERROR] 해당하는 레벨이 존재하지 않습니다.");
}
if (!Mission.contains(missionName)) {
throw new IllegalArgumentException("[ERROR] 해당하는 미션이 존재하지 않습니다.");
}
if (isValidLevel(levelName, missionName)) {
throw new IllegalArgumentException("[ERROR] 레벨과 미션이 일치하지 않습니다.");
}
}

private boolean isValidLevel(String level, String missionName) {
Mission mission = Mission.valueOf(missionName);
String levelOfMission = mission.getLevelMessage();
return level.equals(levelOfMission);
}
}
38 changes: 38 additions & 0 deletions src/main/java/pairmatching/domain/choice/item/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package pairmatching.domain.choice.item;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum Course {
BACKEND("백엔드"),
FRONTEND("프론트엔드");

private final String courseName;

Course(String courseName) {
this.courseName = courseName;
}

public String getCourseName() {
return courseName;
}

public static boolean contains(String name) {
return Arrays.stream(values())
.anyMatch(value -> name.equals(value.getCourseName()));
}

public static List<String> namesOfValues() {
return Arrays.stream(values())
.map(Course::getCourseName)
.collect(Collectors.toList());
}

public static Course valueOfCourse(String courseName) {
return Arrays.stream(values())
.filter(value -> courseName.equals(value.getCourseName()))
.findAny()
.orElseThrow(() -> new IllegalStateException("[ERROR] 존재하지 않는 Course 입니다."));
}
}
34 changes: 34 additions & 0 deletions src/main/java/pairmatching/domain/choice/item/Level.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package pairmatching.domain.choice.item;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum Level {
LEVEL1("레벨1"),
LEVEL2("레벨2"),
LEVEL3("레벨3"),
LEVEL4("레벨4"),
LEVEL5("레벨5");

private final String name;

Level(String name) {
this.name = name;
}

public static boolean contains(String level) {
return Arrays.stream(values())
.anyMatch(value -> level.equals(value.getName()));
}

public String getName() {
return name;
}

public static List<String> namesOfValues() {
return Arrays.stream(values())
.map(Level::getName)
.collect(Collectors.toList());
}
}
46 changes: 46 additions & 0 deletions src/main/java/pairmatching/domain/choice/item/Mission.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package pairmatching.domain.choice.item;

import java.util.Arrays;

public enum Mission {
CAR_RACING("자동차 경주", Level.LEVEL1),
LOTTO("로또", Level.LEVEL1),
NUMBER_BASEBALL("숫자야구게임", Level.LEVEL1),
SHOPPING_BASKET("장바구니", Level.LEVEL2),
PAYMENT("결제", Level.LEVEL2),
SUBWAY_MAP("지하철노선도", Level.LEVEL2),
IMPROVEMENT_OF_PERFORMANCE("성능개선", Level.LEVEL4),
PUBLISHING("배포", Level.LEVEL4);

private final String name;
private final Level level;

Mission(String name, Level level) {
this.name = name;
this.level = level;
}

public static Mission valueOfMission(String missionName) {
return Arrays.stream(values())
.filter(value -> missionName.equals(value.getName()))
.findAny()
.orElseThrow(() -> new IllegalStateException("[ERROR] 존재하지 않는 Mission 입니다."));
}

public String getName() {
return name;
}

public Level getLevel() {
return level;
}

public String getLevelMessage() {
return level.getName();
}

public static boolean contains(String name) {
return Arrays.stream(values())
.anyMatch(value -> name.equals(value.getName()));
}
}
32 changes: 32 additions & 0 deletions src/main/java/pairmatching/domain/command/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package pairmatching.domain.command;

import java.util.Arrays;

public enum Command {
MATCHING("1"),
CHECKING("2"),
RESETTING("3"),
QUITTING("Q");

private final String key;

Command(String key) {
this.key = key;
}

public String getKey() {
return key;
}

public static Command valueOfCommand(String key) {
return Arrays.stream(values())
.filter(value -> key.equals(value.getKey()))
.findAny()
.orElseThrow(() -> new IllegalStateException("[ERROR] 지원하는 명령어가 아닙니다."));
}

public static boolean contains(String command) {
return Arrays.stream(values())
.anyMatch(value -> command.equals(value.getKey()));
}
}
21 changes: 21 additions & 0 deletions src/main/java/pairmatching/domain/command/UserCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package pairmatching.domain.command;

public class UserCommand {

private final Command command;

public UserCommand(String command) {
validate(command);
this.command = Command.valueOfCommand(command);
}

private void validate(String command) {
if (!Command.contains(command)) {
throw new IllegalArgumentException("[ERROR] 지원하는 기능 명령어가 아닙니다.");
}
}

public boolean isCommandOf(Command command) {
return this.command.equals(command);
}
}
20 changes: 20 additions & 0 deletions src/main/java/pairmatching/domain/program/PairMatchingProgram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package pairmatching.domain.program;

import pairmatching.domain.MatchingHistory;
import pairmatching.domain.MatchingMachine;
import pairmatching.domain.choice.Choice;

public class PairMatchingProgram {

private final MatchingHistory history;
private final MatchingMachine machine;

public PairMatchingProgram(MatchingHistory history, MatchingMachine machine) {
this.history = history;
this.machine = machine;
}

public boolean hasMatched(Choice choice) {
return history.hasMatchingOf(choice);
}
}
Loading