-
Notifications
You must be signed in to change notification settings - Fork 491
Expand file tree
/
Copy pathMatchingController.java
More file actions
58 lines (49 loc) · 2.33 KB
/
Copy pathMatchingController.java
File metadata and controls
58 lines (49 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package pairmatching.controller;
import pairmatching.inputview.MatchingInputView;
import pairmatching.outputview.ExceptionHandlingOutputView;
import pairmatching.outputview.MatchingOutputView;
import pairmatching.service.MatchingService;
import pairmatching.system.exception.PairMatchingAlreadyExistException;
import pairmatching.system.exception.SamePairMatchedAtSameLevelException;
import pairmatching.vo.MatchingCommand;
import pairmatching.vo.RematchingCommand;
import java.util.List;
import java.util.Map;
public class MatchingController extends AbstractController {
public static final int DUPLICATING_LIMIT_COUNT = 3;
public static final String MATCHING_FAILED_MESSAGE = "페어 매칭에 실패했습니다.";
@Override
public void doProcess(Map<String, Object> model) {
MatchingCommand matchingCommand = getMatchingCommand();
try {
MatchingService.checkPairMatchingAlreadyExists(matchingCommand.getCourse(), matchingCommand.getMission());
matchPairs(matchingCommand);
} catch (PairMatchingAlreadyExistException e) {
handlePairMatchingAlreadyExistingCondition(matchingCommand);
}
}
private static void matchPairs(MatchingCommand matchingCommand) {
doMatch(matchingCommand, 0);
List<List<String>> pairs
= MatchingService.findAllPairs(matchingCommand.getCourse(), matchingCommand.getMission());
MatchingOutputView.printPairInformation(pairs);
}
private static void doMatch(MatchingCommand matchingCommand, int duplicatedCount) {
try {
MatchingService.doMatch(matchingCommand.getCourse(), matchingCommand.getMission());
} catch (SamePairMatchedAtSameLevelException e) {
if (duplicatedCount == DUPLICATING_LIMIT_COUNT) {
ExceptionHandlingOutputView.printExceptionMessage(MATCHING_FAILED_MESSAGE);
throw e;
}
doMatch(matchingCommand, ++duplicatedCount);
}
}
private static void handlePairMatchingAlreadyExistingCondition(MatchingCommand matchingCommand) {
MatchingOutputView.printAskingReMatchingCommand();
RematchingCommand rematchingCommand = MatchingInputView.getReMatchingCommand();
if (rematchingCommand == RematchingCommand.YES) {
matchPairs(matchingCommand);
}
}
}