forked from FIRST-Tech-Challenge/FtcRobotController
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXCYBoolean.java
More file actions
48 lines (37 loc) · 1.04 KB
/
XCYBoolean.java
File metadata and controls
48 lines (37 loc) · 1.04 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
46
47
48
package org.firstinspires.ftc.teamcode;
import java.util.ArrayList;
import java.util.function.BooleanSupplier;
public class XCYBoolean {
private static final ArrayList<XCYBoolean> allInstance = new ArrayList<>();
private final BooleanSupplier trueCondition;
private boolean current_val = false, last_val;
public XCYBoolean(BooleanSupplier condition) {
trueCondition = condition;
read();
allInstance.add(this);
}
public void read() {
last_val = current_val;
current_val = trueCondition.getAsBoolean();
}
public boolean get() {
return current_val;
}
public boolean toTrue() {
return !last_val && current_val;
}
public boolean toFalse() {
return last_val && !current_val;
}
public boolean isChanged(){
return toFalse()||toTrue();
}
public static void bulkRead() {
for (XCYBoolean b : allInstance) {
b.read();
}
}
public void deactivate(){
allInstance.remove(this);
}
}