-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBridge.java
More file actions
45 lines (36 loc) · 1.12 KB
/
Bridge.java
File metadata and controls
45 lines (36 loc) · 1.12 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
45
package domain;
import java.util.List;
public class Bridge {
private Integer height;
private List<Point> points;
public Bridge(int height,List<Point> points){
this.height = height;
this.points = points;
validateBridge(points);
}
public List<Point> getPoints() {
return points;
}
public Point nextPoint(int currentColumn){
currentColumn --;
Point point = points.get(currentColumn);
if (point.getLinkedType() == LinkedType.RIGHT) {
Point nextPoint = points.get(currentColumn + 1);
return nextPoint;
}
if (point.getLinkedType() == LinkedType.LEFT) {
Point nextPoint = points.get(currentColumn - 1);
return nextPoint;
}
return point;
}
public void validateBridge(List<Point> points){
for(int i = 0 ; i < points.size() - 1 ; i++){
Point current = points.get(i);
Point next = points.get(i+1);
if(current.getLinkedType() == next.getLinkedType()){
throw new IllegalArgumentException();
}
}
}
}