spinningcube/src/main/java/org/apidesign/demo/spinningcube/DataModel.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 09 Jan 2015 06:10:00 +0100
changeset 227 fd26342cf23d
parent 57 9984b9f7d8c6
permissions -rw-r--r--
Switching to HTML/Java@1.1 and bck2brwsr@0.12
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@39
    24
package org.apidesign.demo.spinningcube;
jtulach@39
    25
jtulach@57
    26
import java.util.Arrays;
jtulach@57
    27
import java.util.List;
jtulach@39
    28
import net.java.html.json.ComputedProperty;
jtulach@39
    29
import net.java.html.json.Model;
jtulach@39
    30
import net.java.html.json.Property;
jtulach@39
    31
jtulach@39
    32
/** Model with one message and cube with six sides.
jtulach@39
    33
 *
jtulach@39
    34
 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jtulach@39
    35
 */
jaroslav@227
    36
@Model(className = "Data", targetId = "", properties = {
jtulach@39
    37
    @Property(name = "message", type = String.class),
jtulach@39
    38
})
jtulach@39
    39
final class DataModel {
jtulach@57
    40
    @ComputedProperty static List<String> sides(String message) {
jtulach@39
    41
        String[] arr = new String[6];
jtulach@39
    42
        String[] words = message == null ? new String[0] : message.split(" ", 6);
jtulach@39
    43
        for (int i = 0; i < 6; i++) {
jtulach@39
    44
            arr[i] = words.length > i ? words[i] : "!";
jtulach@39
    45
        }
jtulach@57
    46
        return Arrays.asList(arr);
jtulach@39
    47
    }
jtulach@39
    48
}