-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringPropertyExample.java
111 lines (86 loc) · 2.6 KB
/
StringPropertyExample.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package example;
import com.shimizukenta.property.IntegerCompution;
import com.shimizukenta.property.StringCompution;
import com.shimizukenta.property.StringProperty;
public class StringPropertyExample implements Runnable {
public StringPropertyExample() {
/* Nothing */
}
@Override
public void run() {
try {
System.out.println("run: " + this.getClass());
System.out.println();
/* build instance */
StringProperty p = StringProperty.newInstance();
/* getter */
System.out.println("toString: \"" + p.toString() + "\"");
System.out.println();
/* setter */
System.out.println("set: \"1st\"");
p.set("1st");;
System.out.println("toString: \"" + p.toString() + "\"");
System.out.println();
/* detect value changed */
System.out.println("add change listener, 1st time notify present value.");
p.addChangeListener(v -> {
System.out.println("toString: \"" + v + "\"");
System.out.println();
});
/* set value */
System.out.println("set: \"2nd\"");
p.set("2nd");
new Thread(() -> {
try {
System.out.println("sleep 2000 msec...");
Thread.sleep(2000L);
System.out.println("set: \"3rd\"");
p.set("3rd");
}
catch ( InterruptedException ignore ) {
}
}).start();
System.out.println("Waiting until value is \"3rd\"");
p.waitUntilEqualTo("3rd");
System.out.println();
IntegerCompution length = p.computeLength();
length.addChangeListener(v -> {
System.out.println("length: " + v);
System.out.println();
});
StringCompution toUpperCase = p.computeToUpperCase();
toUpperCase.addChangeListener(v -> {
System.out.println("toUpperCase: \"" + v + "\"");
});
System.out.println("set: \"4th\"");
p.set("4th");
System.out.println();
StringProperty x = StringProperty.newInstance("AAA");
StringProperty y = StringProperty.newInstance("BBB");
StringProperty z = StringProperty.newInstance("CCC");
StringCompution join = StringCompution.join(",", x, y, z);
join.addChangeListener(v -> {
System.out.println("join: \"" + v + "\"");
System.out.println();
});
System.out.println("set: \"111\" to \"AAA\"");
x.set("111");
System.out.println("set: \"222\" to \"BBB\"");
y.set("222");
System.out.println("set: \"333\" to \"CCC\"");
z.set("333");
System.out.println();
System.out.println("reach end");
}
catch ( InterruptedException ignore ) {
}
}
public static void main(String[] args) {
try {
new StringPropertyExample().run();
}
catch ( Throwable t ) {
t.printStackTrace();
}
}
}