use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.
the class PrintlnFunctionUnitTest method testCall_WithOneArgument.
@Test
public void testCall_WithOneArgument() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));
this.fun.call(null, new AviatorString("hello"));
out.flush();
out.close();
String lineSeparator = System.getProperty("line.separator");
byte[] data = out.toByteArray();
assertEquals("hello" + lineSeparator, new String(data));
}
use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.
the class SeqFilterFunctionUnitTest method testFilter_map.
@Test
public void testFilter_map() {
Map<Integer, String> data = new HashMap<>();
for (int i = 0; i < 5; i++) {
data.put(i, "a" + i);
}
Map<String, Object> env = new HashMap<>();
SeqPredicateFunction predicate = new SeqPredicateFunction("eq_temp_1", OperatorType.EQ, new AviatorString("a1"), new AviatorString("value"));
env.putAll(AviatorEvaluator.FUNC_MAP);
env.put("eq_temp_1", predicate);
SeqFilterFunction fun = new SeqFilterFunction();
AviatorObject result = fun.call(env, AviatorRuntimeJavaType.valueOf(data), new AviatorJavaType("eq_temp_1"));
Map map = ((Map) result.getValue(null));
assertEquals(1, map.size());
for (Object value : map.values()) {
assertEquals("a1", value.toString());
}
}
use of com.googlecode.aviator.runtime.type.AviatorString in project aviatorscript by killme2008.
the class SeqPredicateFunctionUnitTest method testPredicate_property.
@Test
public void testPredicate_property() {
Map<String, String> data = new HashMap<>();
for (int i = 0; i < 5; i++) {
data.put("key" + i, "value" + i);
}
SeqPredicateFunction predicate = new SeqPredicateFunction("eq_temp_1", OperatorType.EQ, new AviatorString("value1"), new AviatorString("key1"));
AviatorObject result = predicate.call(null, AviatorRuntimeJavaType.valueOf(data));
assertTrue(result.booleanValue(null));
}
use of com.googlecode.aviator.runtime.type.AviatorString in project graphql-calculator by graphql-calculator.
the class ListMapper method call.
@Override
public AviatorObject call(Map<String, Object> env, AviatorObject listNameObj, AviatorObject expressionObj) {
String expression = ((AviatorString) expressionObj).getLexeme(Collections.emptyMap());
if (expression == null || expression.isEmpty()) {
return AviatorNil.NIL;
}
String listPath = ((AviatorString) listNameObj).getLexeme(Collections.emptyMap());
List<Object> listValue = (List<Object>) AviatorEvaluator.execute(listPath, env);
if (listValue == null) {
return AviatorNil.NIL;
}
Map<Object, Object> result = listValue.stream().collect(Collectors.toMap(Function.identity(), ele -> {
HashMap<String, Object> expEnv = new HashMap<>(env);
expEnv.put("ele", ele);
return AviatorEvaluator.execute(expression, expEnv, true);
}));
return AviatorRuntimeJavaType.valueOf(result);
}
use of com.googlecode.aviator.runtime.type.AviatorString in project graphql-calculator by graphql-calculator.
the class ToMap method call.
@Override
public AviatorObject call(Map<String, Object> env, AviatorObject listElement, AviatorObject fieldNameObj) {
String fieldName = ((AviatorString) fieldNameObj).getLexeme(Collections.emptyMap());
Collection<Object> list = (Collection<Object>) listElement.getValue(Collections.emptyMap());
if (list == null || list.isEmpty()) {
return AviatorRuntimeJavaType.valueOf(Collections.emptyMap());
}
Map<Object, Object> result = new LinkedHashMap<>();
for (Object ele : list) {
Map<String, Object> objectMap = toMap(ele);
result.putIfAbsent(objectMap.get(fieldName), objectMap);
}
return AviatorRuntimeJavaType.valueOf(result);
}
Aggregations