-
Notifications
You must be signed in to change notification settings - Fork 748
/
Copy pathLine.java
45 lines (36 loc) · 1.32 KB
/
Line.java
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
package nextstep.ladder.domain;
import nextstep.ladder.util.RandomUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Line {
private List<Point> points;
public Line(int pointSize) {
this.points = createPoints(pointSize);
}
public List<Point> getPoints() {
return Collections.unmodifiableList(points);
}
private List<Point> createPoints(int pointSize) {
List<Point> points = new ArrayList<>();
for (int index = 0; index < pointSize; index++) {
addPoint(points, index, pointSize);
}
return points;
}
private void addPoint(List<Point> points, int index, int pointSize) {
int totalSizeBound = PointStatus.TOTAL_INDEX_SIZE;
int twoResultSizeBound = PointStatus.TWO_RESULT_SIZE;
if (index == 0) {
points.add(Point.createFirst(() -> RandomUtil.generator(twoResultSizeBound)));
return;
}
if (pointSize - 1 == index) {
points.add(Point.createLast(() -> RandomUtil.generator(twoResultSizeBound), points.get(index - 1)));
return;
}
Point point = Point.create(() -> RandomUtil.generator(totalSizeBound), points.get(index - 1));
// LEFT 일때 points list 값 바꾸기
points.add(point);
}
}