-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberComputionExample.java
86 lines (68 loc) · 2.2 KB
/
NumberComputionExample.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
package example;
import com.shimizukenta.property.IntegerProperty;
import com.shimizukenta.property.NumberCompution;
public class NumberComputionExample implements Runnable {
public NumberComputionExample() {
/* Nothing */
}
@Override
public void run() {
System.out.println("run: " + this.getClass());
System.out.println();
/* build instance */
final IntegerProperty a = IntegerProperty.newInstance(1);
final IntegerProperty b = IntegerProperty.newInstance(2);
final IntegerProperty c = IntegerProperty.newInstance(3);
/* getter */
System.out.println("get a: " + a.intValue());
System.out.println("get b: " + b.intValue());
System.out.println("get c: " + c.intValue());
System.out.println();
/* build NumberCompution */
NumberCompution addA2 = a.add(2);
NumberCompution addBC = b.add(c);
NumberCompution mulBC = b.multiply(c);
NumberCompution subBC = b.subtract(c);
NumberCompution negateA = a.negate();
System.out.println("a + 2 = " + addA2.intValue());
System.out.println("b + c = " + addBC.intValue());
System.out.println("b * c = " + mulBC.intValue());
System.out.println("b - c = " + subBC.intValue());
System.out.println("-a = " + negateA.intValue());
System.out.println();
/* detect value changed */
System.out.println("add change listeners, 1st time notify present status.");
NumberCompution sumABC = NumberCompution.sum(a, b, c);
sumABC.addChangeListener(v -> {
System.out.println("sum(a, b, c): " + v);
});
//
NumberCompution maxABC = NumberCompution.max(a, b, c);
maxABC.addChangeListener(v -> {
System.out.println("max(a, b, c): " + v);
});
NumberCompution minABC = NumberCompution.min(a, b, c);
minABC.addChangeListener(v -> {
System.out.println("min(a, b, c): " + v);
});
System.out.println();
System.out.println("set a: " + 4);
a.set(4);
System.out.println();
System.out.println("set b: " + 5);
b.set(5);;
System.out.println();
System.out.println("set c: " + 6);
c.set(6);;
System.out.println();
System.out.println("reach end");
}
public static void main(String[] args) {
try {
new NumberComputionExample().run();
}
catch ( Throwable t ) {
t.printStackTrace();
}
}
}