File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed
src/main/java/nextstep/ladder/domain Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change 1
1
package nextstep .ladder .domain ;
2
2
3
3
import java .util .List ;
4
- import java .util .stream .Collectors ;
5
4
import java .util .stream .IntStream ;
6
5
6
+ import static java .util .stream .Collectors .collectingAndThen ;
7
+ import static java .util .stream .Collectors .toList ;
8
+
7
9
public class Lines {
8
10
9
11
private final List <Line > lines ;
@@ -20,10 +22,9 @@ private void validate(List<Line> lines) {
20
22
}
21
23
22
24
public static Lines of (int numberOfPlayers , int height ) {
23
- List < Line > lines = IntStream .range (0 , height )
25
+ return IntStream .range (0 , height )
24
26
.mapToObj (i -> LineBuilder .buildWithRandomPoints (numberOfPlayers ))
25
- .collect (Collectors .toList ());
26
- return new Lines (lines );
27
+ .collect (collectingAndThen (toList (), Lines ::new ));
27
28
}
28
29
29
30
public int getHeight () {
Original file line number Diff line number Diff line change 1
1
package nextstep .ladder .domain ;
2
2
3
3
import java .util .List ;
4
- import java .util .stream .Collectors ;
5
4
import java .util .stream .IntStream ;
6
5
6
+ import static java .util .stream .Collectors .collectingAndThen ;
7
+ import static java .util .stream .Collectors .toList ;
8
+
7
9
public class Players {
8
10
private final List <Player > players ;
9
11
@@ -19,11 +21,9 @@ private void validate(List<Player> players) {
19
21
}
20
22
21
23
public static Players of (List <String > playerNames ) {
22
- List < Player > players = IntStream .range (0 , playerNames .size ())
24
+ return IntStream .range (0 , playerNames .size ())
23
25
.mapToObj (index -> new Player (index , playerNames .get (index )))
24
- .collect (Collectors .toList ());
25
-
26
- return new Players (players );
26
+ .collect (collectingAndThen (toList (), Players ::new ));
27
27
}
28
28
29
29
public int count () {
You can’t perform that action at this time.
0 commit comments