jtulach@39
|
1 |
/**
|
jtulach@39
|
2 |
* The MIT License (MIT)
|
jtulach@39
|
3 |
*
|
jtulach@39
|
4 |
* Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jtulach@39
|
5 |
*
|
jtulach@39
|
6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
jtulach@39
|
7 |
* of this software and associated documentation files (the "Software"), to deal
|
jtulach@39
|
8 |
* in the Software without restriction, including without limitation the rights
|
jtulach@39
|
9 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
jtulach@39
|
10 |
* copies of the Software, and to permit persons to whom the Software is
|
jtulach@39
|
11 |
* furnished to do so, subject to the following conditions:
|
jtulach@39
|
12 |
*
|
jtulach@39
|
13 |
* The above copyright notice and this permission notice shall be included in
|
jtulach@39
|
14 |
* all copies or substantial portions of the Software.
|
jtulach@39
|
15 |
*
|
jtulach@39
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
jtulach@39
|
17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
jtulach@39
|
18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
jtulach@39
|
19 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
jtulach@39
|
20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
jtulach@39
|
21 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
jtulach@39
|
22 |
* THE SOFTWARE.
|
jtulach@39
|
23 |
*/
|
jtulach@46
|
24 |
package org.apidesign.demo.words;
|
jtulach@39
|
25 |
|
jtulach@56
|
26 |
import java.util.ArrayList;
|
jtulach@56
|
27 |
import java.util.List;
|
jtulach@39
|
28 |
import net.java.html.json.ComputedProperty;
|
jtulach@46
|
29 |
import net.java.html.json.Function;
|
jtulach@39
|
30 |
import net.java.html.json.Model;
|
jtulach@39
|
31 |
import net.java.html.json.Property;
|
jtulach@39
|
32 |
|
jtulach@39
|
33 |
/** Model with one message and cube with six sides.
|
jtulach@39
|
34 |
*
|
jtulach@39
|
35 |
* @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jtulach@39
|
36 |
*/
|
jaroslav@227
|
37 |
@Model(className = "Data", targetId = "", properties = {
|
jtulach@39
|
38 |
@Property(name = "message", type = String.class),
|
jtulach@46
|
39 |
@Property(name = "on", type = boolean.class)
|
jtulach@39
|
40 |
})
|
jtulach@39
|
41 |
final class DataModel {
|
jtulach@56
|
42 |
@ComputedProperty static List<String> sides(String message) {
|
jtulach@56
|
43 |
List<String> arr = new ArrayList<>();
|
jtulach@39
|
44 |
String[] words = message == null ? new String[0] : message.split(" ", 6);
|
jtulach@39
|
45 |
for (int i = 0; i < 6; i++) {
|
jtulach@56
|
46 |
arr.add(words.length > i ? words[i] : "!");
|
jtulach@39
|
47 |
}
|
jtulach@39
|
48 |
return arr;
|
jtulach@39
|
49 |
}
|
jtulach@46
|
50 |
|
jtulach@46
|
51 |
@Function static void turnOn(Data model) {
|
jtulach@46
|
52 |
model.setOn(true);
|
jtulach@46
|
53 |
}
|
jtulach@46
|
54 |
@Function static void turnOff(Data model) {
|
jtulach@46
|
55 |
model.setOn(false);
|
jtulach@46
|
56 |
}
|
jtulach@39
|
57 |
}
|