-
Notifications
You must be signed in to change notification settings - Fork 746
/
Copy pathAdjacentVerticalLines.java
43 lines (34 loc) · 1.63 KB
/
AdjacentVerticalLines.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
package ladder.domain;
import ladder.exception.IllegalAdjacentVerticalLinesException;
public class AdjacentVerticalLines {
private final VerticalLine leftVerticalLine;
private final VerticalLine rightVerticalLine;
public AdjacentVerticalLines(VerticalLine firstVerticalLine, VerticalLine secondVerticalLine) {
checkAdjacentVerticalLines(firstVerticalLine, secondVerticalLine);
this.leftVerticalLine = min(firstVerticalLine, secondVerticalLine);
this.rightVerticalLine = max(firstVerticalLine, secondVerticalLine);
}
public VerticalLine getLeftVerticalLine() {
return leftVerticalLine;
}
public VerticalLine getRightVerticalLine() {
return rightVerticalLine;
}
private void checkAdjacentVerticalLines(VerticalLine firstVerticalLine, VerticalLine secondVerticalLine) {
if (Math.abs(firstVerticalLine.getIndex() - secondVerticalLine.getIndex()) > 1) {
throw new IllegalAdjacentVerticalLinesException(
String.format("입력된 인덱스 : %d, %d", firstVerticalLine.getIndex(), secondVerticalLine.getIndex())
);
}
}
private VerticalLine max(VerticalLine firstVerticalLine, VerticalLine secondVerticalLine) {
return firstVerticalLine.getIndex() > secondVerticalLine.getIndex()
? firstVerticalLine
: secondVerticalLine;
}
private VerticalLine min(VerticalLine firstVerticalLine, VerticalLine secondVerticalLine) {
return firstVerticalLine.getIndex() > secondVerticalLine.getIndex()
? secondVerticalLine
: firstVerticalLine;
}
}