-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathBridgeLine.java
42 lines (33 loc) · 1.12 KB
/
BridgeLine.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
package ladder.domain;
import java.util.List;
import java.util.Objects;
import java.util.stream.IntStream;
public class BridgeLine {
private final List<Boolean> connections;
public BridgeLine(final List<Boolean> connections) {
this.connections = connections;
}
public int getHeight() {
return this.connections.size();
}
public boolean isConnected(final int height) {
return this.connections.get(height);
}
public boolean hasSameHeightConnection(final BridgeLine bridgeLine) {
return IntStream.range(0, this.connections.size())
.filter(height -> this.connections.get(height) && bridgeLine.connections.get(height))
.findFirst()
.isPresent();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BridgeLine that = (BridgeLine) o;
return Objects.equals(connections, that.connections);
}
@Override
public int hashCode() {
return Objects.hash(connections);
}
}