use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class ForEachNode method getReducedValueAccelerated.
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
ItemResolverFactory.ItemResolver itemR = new ItemResolverFactory.ItemResolver(item);
ItemResolverFactory itemFactory = new ItemResolverFactory(itemR, new DefaultLocalVariableResolverFactory(factory));
Object iterCond = condition.getValue(ctx, thisValue, factory);
if (type == -1) {
determineIterType(iterCond.getClass());
}
Object v;
switch(type) {
case ARRAY:
int len = Array.getLength(iterCond);
for (int i = 0; i < len; i++) {
itemR.setValue(Array.get(iterCond, i));
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
break;
case CHARSEQUENCE:
for (Object o : iterCond.toString().toCharArray()) {
itemR.setValue(o);
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
break;
case INTEGER:
int max = (Integer) iterCond + 1;
for (int i = 1; i != max; i++) {
itemR.setValue(i);
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
break;
case ITERABLE:
for (Object o : (Iterable) iterCond) {
itemR.setValue(o);
v = compiledBlock.getValue(ctx, thisValue, itemFactory);
if (itemFactory.tiltFlag())
return v;
}
break;
}
return null;
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class ForNode method getReducedValueAccelerated.
public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) {
VariableResolverFactory ctxFactory = indexAlloc ? factory : new MapVariableResolverFactory(new HashMap<String, Object>(1), factory);
Object v;
for (initializer.getValue(ctx, thisValue, ctxFactory); (Boolean) condition.getValue(ctx, thisValue, ctxFactory); after.getValue(ctx, thisValue, ctxFactory)) {
v = compiledBlock.getValue(ctx, thisValue, ctxFactory);
if (ctxFactory.tiltFlag())
return v;
}
return null;
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class Function method call.
public Object call(Object ctx, Object thisValue, VariableResolverFactory factory, Object[] parms) {
if (parms != null && parms.length != 0) {
// detect tail recursion
if (factory instanceof FunctionVariableResolverFactory && ((FunctionVariableResolverFactory) factory).getIndexedVariableResolvers().length == parms.length) {
FunctionVariableResolverFactory fvrf = (FunctionVariableResolverFactory) factory;
if (fvrf.getFunction().equals(this)) {
VariableResolver[] swapVR = fvrf.getIndexedVariableResolvers();
fvrf.updateParameters(parms);
try {
return compiledBlock.getValue(ctx, thisValue, fvrf);
} finally {
fvrf.setIndexedVariableResolvers(swapVR);
}
}
}
return compiledBlock.getValue(thisValue, new FunctionVariableResolverFactory(this, factory, parameters, parms));
} else if (cMode) {
return compiledBlock.getValue(thisValue, new DefaultLocalVariableResolverFactory(factory, parameters).setNoTilt(true));
} else {
return compiledBlock.getValue(thisValue, new DefaultLocalVariableResolverFactory(factory, parameters).setNoTilt(true));
}
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class IndexedOperativeAssign method getReducedValue.
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
VariableResolver resolver = factory.getIndexedVariableResolver(register);
resolver.setValue(ctx = MathProcessor.doOperations(resolver.getValue(), operation, eval(expr, start, offset, ctx, factory)));
return ctx;
}
use of org.mvel2.integration.VariableResolverFactory in project mvel by mikebrock.
the class Strsim method getReducedValue.
public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) {
try {
String i = String.valueOf(soundslike.getReducedValue(ctx, thisValue, factory));
if (i == null)
throw new ClassCastException();
String x = (String) stmt.getReducedValue(ctx, thisValue, factory);
if (x == null)
throw new CompileException("not a string: " + stmt.getName(), stmt.getExpr(), getStart());
return similarity(i, x);
} catch (ClassCastException e) {
throw new CompileException("not a string: " + soundslike.getName(), soundslike.getExpr(), soundslike.getStart());
}
}
Aggregations