-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathLadderRow.java
More file actions
35 lines (28 loc) · 1012 Bytes
/
LadderRow.java
File metadata and controls
35 lines (28 loc) · 1012 Bytes
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
package domain;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import java.util.function.Consumer;
public class LadderRow {
private final List<Boolean> columns = new ArrayList<>();
public LadderRow(int width, Supplier<Boolean> connectionFunction) {
initializeColumns(width, connectionFunction);
}
private void initializeColumns(int width, Supplier<Boolean> connectionFunction) {
boolean prevPoint = false;
for (int i = 0; i < width - 1; i++) {
boolean isConnected = determineConnection(prevPoint, connectionFunction);
columns.add(isConnected);
prevPoint = isConnected;
}
}
private boolean determineConnection(boolean prevPoint, Supplier<Boolean> connectionFunction) {
if (prevPoint) {
return false;
}
return connectionFunction.get();
}
public void forEach(Consumer<Boolean> consumer) {
columns.forEach(consumer);
}
}