-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathHorizontalLines.java
More file actions
44 lines (34 loc) · 1.3 KB
/
HorizontalLines.java
File metadata and controls
44 lines (34 loc) · 1.3 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
package ladder.domain;
import ladder.exception.IllegalHorizontalLineHeightException;
import java.util.Set;
import java.util.stream.Collectors;
public class HorizontalLines {
private final Set<HorizontalLine> horizontalLineSet;
private final int maxHeight;
public HorizontalLines(Set<HorizontalLine> horizontalLineSet, int maxHeight) {
checkValidHorizontalLineHeight(horizontalLineSet, maxHeight);
this.horizontalLineSet = horizontalLineSet;
this.maxHeight = maxHeight;
}
private void checkValidHorizontalLineHeight(Set<HorizontalLine> horizontalLineSet, int maxHeight) {
if (horizontalLineSet.stream()
.anyMatch(it -> it.getHeight() >= maxHeight)
) {
throw new IllegalHorizontalLineHeightException(String.format("최대 높이 : %d", maxHeight));
}
}
public Set<HorizontalLine> getHorizontalLineSet() {
return Set.copyOf(horizontalLineSet);
}
public Set<HorizontalLine> getHorizontalLineSetByHeight(int height) {
return horizontalLineSet.stream()
.filter(it -> it.getHeight() == height)
.collect(Collectors.toSet());
}
public int getMaxHeight() {
return maxHeight;
}
public int getSize() {
return horizontalLineSet.size();
}
}