use of com.googlecode.aviator.runtime.type.AviatorFunction in project aviatorscript by killme2008.
the class SeqNotAnyFunction method call.
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
Object first = arg1.getValue(env);
AviatorFunction fun = FunctionUtils.getFunction(arg2, env, 1);
if (fun == null) {
throw new FunctionNotFoundException("There is no function named " + ((AviatorJavaType) arg2).getName());
}
if (first == null) {
return AviatorBoolean.TRUE;
}
for (Object obj : RuntimeUtils.seq(first, env)) {
if (fun.call(env, AviatorRuntimeJavaType.valueOf(obj)).booleanValue(env)) {
return AviatorBoolean.FALSE;
}
}
return AviatorBoolean.TRUE;
}
use of com.googlecode.aviator.runtime.type.AviatorFunction in project aviatorscript by killme2008.
the class SeqReduceFunction method call.
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2, final AviatorObject arg3) {
Object first = arg1.getValue(env);
AviatorFunction fun = FunctionUtils.getFunction(arg2, env, 2);
if (fun == null) {
throw new FunctionNotFoundException("There is no function named " + ((AviatorJavaType) arg2).getName());
}
if (first == null) {
return arg3;
}
AviatorObject result = arg3;
for (Object obj : RuntimeUtils.seq(first, env)) {
result = fun.call(env, result, AviatorRuntimeJavaType.valueOf(obj));
}
return result;
}
use of com.googlecode.aviator.runtime.type.AviatorFunction in project aviatorscript by killme2008.
the class SeqSomeFunction method call.
@Override
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
Object first = arg1.getValue(env);
AviatorFunction fun = FunctionUtils.getFunction(arg2, env, 1);
if (fun == null) {
throw new FunctionNotFoundException("There is no function named " + ((AviatorJavaType) arg2).getName());
}
if (first == null) {
return AviatorNil.NIL;
}
for (Object obj : RuntimeUtils.seq(first, env)) {
// return first fun returns true element.
if (fun.call(env, AviatorRuntimeJavaType.valueOf(obj)).booleanValue(env)) {
return AviatorRuntimeJavaType.valueOf(obj);
}
}
// else return nil
return AviatorNil.NIL;
}
use of com.googlecode.aviator.runtime.type.AviatorFunction in project aviatorscript by killme2008.
the class SeqMapFunction method call.
@Override
@SuppressWarnings({ "rawtypes" })
public AviatorObject call(final Map<String, Object> env, final AviatorObject arg1, final AviatorObject arg2) {
Object first = arg1.getValue(env);
AviatorFunction fun = FunctionUtils.getFunction(arg2, env, 1);
if (fun == null) {
throw new FunctionNotFoundException("There is no function named " + ((AviatorJavaType) arg2).getName());
}
if (first == null) {
return AviatorNil.NIL;
}
Sequence seq = RuntimeUtils.seq(first, env);
Collector collector = seq.newCollector(seq.hintSize());
for (Object obj : seq) {
collector.add(fun.call(env, AviatorRuntimeJavaType.valueOf(obj)).getValue(env));
}
return AviatorRuntimeJavaType.valueOf(collector.getRawContainer());
}
Aggregations