-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathResultPosition.java
More file actions
43 lines (32 loc) · 1.25 KB
/
ResultPosition.java
File metadata and controls
43 lines (32 loc) · 1.25 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
package nextstep.ladder.domain.laddergame.position;
import nextstep.ladder.domain.ladder.LadderResult;
import nextstep.ladder.domain.laddergame.LadderGameResult;
import nextstep.ladder.domain.player.Players;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.IntStream;
public class ResultPosition {
private final Map<Integer, Integer> positionMap;
public ResultPosition() {
this(new HashMap<>());
}
public ResultPosition(Map<Integer, Integer> positionMap) {
this.positionMap = positionMap;
}
public void add(int start, int finish) {
positionMap.put(start, finish);
}
public int getFinishPosition(int startPosition) {
return positionMap.get(startPosition);
}
public LadderGameResult match(Players players, LadderResult ladderResult) {
LadderGameResult ladderGameResult = new LadderGameResult();
IntStream.range(0, players.getPlayers().size())
.forEach(i -> {
String name = players.getPlayers().get(i).getName();
String result = ladderResult.getResultByIndex(getFinishPosition(i));
ladderGameResult.add(name, result);
});
return ladderGameResult;
}
}