use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.
the class SeqReduceFunctionUnitTest method testReduce_IllegalArguments.
@Test(expected = IllegalArgumentException.class)
public void testReduce_IllegalArguments() {
LinkedHashSet<Integer> a = new LinkedHashSet<Integer>();
for (int i = 0; i < 10; i++) {
a.add(i);
}
SeqReduceFunction fun = new SeqReduceFunction();
AviatorObject result = fun.call(this.env, AviatorRuntimeJavaType.valueOf(a), new AviatorJavaType("+"));
}
use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.
the class SeqSortFunctionUnitTest method testSort_Array.
@Test
public void testSort_Array() {
Integer[] a = new Integer[10];
int index = 0;
for (int i = 9; i >= 0; i--) {
a[index++] = i;
}
SeqSortFunction fun = new SeqSortFunction();
AviatorObject result = fun.call(null, AviatorRuntimeJavaType.valueOf(a));
index = 0;
Integer[] dup = (Integer[]) result.getValue(null);
assertFalse(Arrays.equals(a, dup));
for (Integer i : dup) {
assertEquals(i, index++);
}
}
use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.
the class SeqSortFunctionUnitTest method testSort_HashSet.
@Test(expected = IllegalArgumentException.class)
public void testSort_HashSet() {
Set<Integer> a = new HashSet<Integer>();
int index = 0;
for (int i = 9; i >= 0; i--) {
a.add(i);
}
SeqSortFunction fun = new SeqSortFunction();
AviatorObject result = fun.call(null, AviatorRuntimeJavaType.valueOf(a));
}
use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.
the class SeqSortFunctionUnitTest method testSort_List.
@Test
public void testSort_List() {
List<Integer> a = new ArrayList<Integer>();
int index = 0;
for (int i = 9; i >= 0; i--) {
a.add(i);
}
SeqSortFunction fun = new SeqSortFunction();
AviatorObject result = fun.call(null, AviatorRuntimeJavaType.valueOf(a));
index = 0;
List<Integer> dup = (List<Integer>) result.getValue(null);
assertFalse(a.equals(dup));
System.out.println(a);
System.out.println(dup);
for (Integer i : dup) {
assertEquals(i, index++);
}
}
use of com.googlecode.aviator.runtime.type.AviatorObject in project aviatorscript by killme2008.
the class SeqArrayFunction method variadicCall.
@Override
public AviatorObject variadicCall(final Map<String, Object> env, final AviatorObject... args) {
if (args == null || args.length == 0) {
throw new IllegalArgumentException("Missing arguments for seq.array");
}
AviatorObject clazzVar = args[0];
if (clazzVar == null || clazzVar.getAviatorType() != AviatorType.JavaType) {
throw new IllegalArgumentException("Invalid class:" + (clazzVar == null ? "null" : clazzVar.desc(env)));
}
try {
String name = ((AviatorJavaType) clazzVar).getName();
Class<?> clazz = null;
if (TypeUtils.PRIMITIVE_TYPES.containsKey(name)) {
clazz = TypeUtils.PRIMITIVE_TYPES.get(name);
} else {
assert (env instanceof Env);
clazz = ((Env) env).resolveClassSymbol(name);
}
Object ret = Array.newInstance(clazz, args.length - 1);
for (int i = 1; i < args.length; i++) {
ArrayUtils.set(ret, i - 1, Reflector.boxArg(clazz, args[i].getValue(env)));
}
return AviatorRuntimeJavaType.valueOf(ret);
} catch (Throwable t) {
throw Reflector.sneakyThrow(t);
}
}
Aggregations