-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlow.java
38 lines (29 loc) · 925 Bytes
/
Flow.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
package core;
import neural.Action;
import neural.Reception;
import java.util.List;
import java.util.function.BooleanSupplier;
import java.util.stream.Stream;
public enum Flow {
RUN, STILL;
public static Flow of(boolean b) {
return b ? RUN : STILL;
}
public static Flow from(BooleanSupplier supplier) {
return of(supplier.getAsBoolean());
}
public static Flow convergeForward(List<Reception> receptions) {
return receptions.stream().anyMatch(f -> f.getForward() == Flow.RUN) ? Flow.RUN : Flow.STILL;
}
public static Flow convergeBackward(List<Action> actions) {
return actions.stream().anyMatch(f -> f.getBackward() == Flow.RUN) ? Flow.RUN : Flow.STILL;
}
public void start(Runnable runnable) {
if (this == RUN) {
runnable.run();
}
}
public Flow inverted(){
return this == RUN ? STILL : RUN;
}
}