-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogicalComputionExample.java
91 lines (70 loc) · 1.98 KB
/
LogicalComputionExample.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package example;
import com.shimizukenta.property.BooleanCompution;
import com.shimizukenta.property.BooleanProperty;
public class LogicalComputionExample implements Runnable {
public LogicalComputionExample() {
/* Nothing */
}
@Override
public void run() {
try {
System.out.println("run: " + this.getClass());
System.out.println();
/* build instance */
final BooleanProperty a = BooleanProperty.newInstance(false);
final BooleanProperty b = BooleanProperty.newInstance(false);
/* getter */
System.out.println("get a: " + a.booleanValue());
System.out.println("get b: " + b.booleanValue());
System.out.println();
/* build LogicalCompution */
BooleanCompution and = a.and(b);
BooleanCompution or = a.or(b);
BooleanCompution not = a.not();
BooleanCompution xor = a.xor(b);
/* detect value changed */
System.out.println("add change listeners, 1st time notify present status.");
and.addChangeListener(v -> {
System.out.println("a&&b : " + v);
});
or.addChangeListener(v -> {
System.out.println("a||b : " + v);
});
not.addChangeListener(v -> {
System.out.println("!a : " + v);
});
xor.addChangeListener(v -> {
System.out.println("a^b : " + v);
});
System.out.println();
System.out.println("set a: " + true);
a.set(true);
new Thread(() -> {
try {
System.out.println();
System.out.println("sleep 2000 msec...");
Thread.sleep(2000L);
System.out.println("set b: " + true);
b.set(true);
}
catch ( InterruptedException ignore ) {
}
}).start();
System.out.println();
System.out.println("waiting until a&&b is true...");
and.waitUntilTrue();
System.out.println();
System.out.println("reach end");
}
catch ( InterruptedException ignore ) {
}
}
public static void main(String[] args) {
try {
new LogicalComputionExample().run();
}
catch ( Throwable t ) {
t.printStackTrace();
}
}
}