use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.
the class StringJoinFunction method join.
private AviatorObject join(final Map<String, Object> env, final AviatorObject arg1, final Object target, final String split) {
Class<?> clazz = target.getClass();
StringBuilder sb = new StringBuilder(50);
if (Collection.class.isAssignableFrom(clazz)) {
boolean wasFirst = true;
for (Object obj : (Collection<?>) target) {
wasFirst = append(sb, split, wasFirst, obj);
}
} else if (clazz.isArray()) {
int length = ArrayUtils.getLength(target);
boolean wasFirst = true;
for (int i = 0; i < length; i++) {
Object obj = ArrayUtils.get(target, i);
wasFirst = append(sb, split, wasFirst, obj);
}
} else {
throw new IllegalArgumentException(arg1.desc(env) + " is not a seq");
}
return new AviatorString(sb.toString());
}
use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.
the class RandomFunctionUnitTest method testCallWithOneArg.
public void testCallWithOneArg() {
RandomFunction rand = new RandomFunction();
AviatorObject result = rand.call(null, AviatorRuntimeJavaType.valueOf(1));
assertTrue(((Integer) result.getValue(null)) < 1);
assertTrue(((Integer) result.getValue(null)) >= 0);
}
use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.
the class RandomFunctionUnitTest method testCallIllegalArgument.
@Test(expected = IllegalArgumentException.class)
public void testCallIllegalArgument() {
RandomFunction rand = new RandomFunction();
AviatorObject result = rand.call(null, AviatorRuntimeJavaType.valueOf(1), AviatorRuntimeJavaType.valueOf(2));
}
use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.
the class BinaryFunctionUnitTest method testModFunction.
@Test
public void testModFunction() {
BinaryFunction fun = new BinaryFunction(OperatorType.MOD);
AviatorObject result = fun.call(env, AviatorLong.valueOf(10L), AviatorLong.valueOf(11L));
assertEquals(10L, (Long) result.getValue(null), 0L);
}
use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.
the class BinaryFunctionUnitTest method testAddFunction.
@Test
public void testAddFunction() {
BinaryFunction fun = new BinaryFunction(OperatorType.ADD);
AviatorObject result = fun.call(env, AviatorLong.valueOf(10L), AviatorLong.valueOf(11L));
assertEquals(21L, (Long) result.getValue(null), 0L);
}
Aggregations