Search in sources :

Example 1 with BtrpString

use of org.btrplace.btrpsl.element.BtrpString in project scheduler by btrplace.

the class ScriptBuilderTest method testStringSupport.

public void testStringSupport() throws ScriptBuilderException {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Script v = b.build("namespace foo; VM[1..10] : tiny;\n$arr = {\"foo\",\"bar\", \"baz\"};$arr2 = $arr + {\"git\"}; $out = \"come \" + \"out \" + 5 + \" \" + VM1; export $arr2,$out to *;");
    BtrpString out = (BtrpString) v.getImportable("$out");
    BtrpSet arr2 = (BtrpSet) v.getImportable("$arr2");
    Assert.assertEquals(out.toString(), "come out 5 foo.VM1");
    Assert.assertEquals(arr2.size(), 4);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) BtrpString(org.btrplace.btrpsl.element.BtrpString) BtrpSet(org.btrplace.btrpsl.element.BtrpSet)

Example 2 with BtrpString

use of org.btrplace.btrpsl.element.BtrpString in project scheduler by btrplace.

the class EnumVar method expand.

/**
 * Expand the enumeration.
 * Variables are not evaluated nor checked
 *
 * @return a set of string or an error
 */
public BtrpOperand expand() {
    String head = getChild(0).getText().substring(0, getChild(0).getText().length() - 1);
    String tail = getChild(getChildCount() - 1).getText().substring(1);
    BtrpSet res = new BtrpSet(1, BtrpOperand.Type.STRING);
    for (int i = 1; i < getChildCount() - 1; i++) {
        BtrpOperand op = getChild(i).go(this);
        if (op == IgnorableOperand.getInstance()) {
            return op;
        }
        BtrpSet s = (BtrpSet) op;
        for (BtrpOperand o : s.getValues()) {
            // Compose
            res.getValues().add(new BtrpString(head + o.toString() + tail));
        }
    }
    return res;
}
Also used : BtrpOperand(org.btrplace.btrpsl.element.BtrpOperand) BtrpSet(org.btrplace.btrpsl.element.BtrpSet) BtrpString(org.btrplace.btrpsl.element.BtrpString) BtrpString(org.btrplace.btrpsl.element.BtrpString)

Aggregations

BtrpSet (org.btrplace.btrpsl.element.BtrpSet)2 BtrpString (org.btrplace.btrpsl.element.BtrpString)2 BtrpOperand (org.btrplace.btrpsl.element.BtrpOperand)1 DefaultModel (org.btrplace.model.DefaultModel)1