本文章介绍运用QLExpress脚本语言进行递归运算,请看下面举的例子,代码如下:
public class RecursivelyTest {
private static final ExpressRunner runner = new ExpressRunner();
private static final ExpressRunner runnerInner = new ExpressRunner();
static {
Operator exeOperator = new Operator() {
@Override
public Object executeInner(Object[] list) throws Exception {
System.out.println("executeInner:r_exeAll");
IExpressContext<String, Object> context = new DefaultContext<>();
runnerInner.execute("1+2", context, null, false, true);
System.out.println(list[0]);
return null;
}
};
runner.addFunction("r_exeAll", exeOperator);
runnerInner.addFunction("r_exeAll", exeOperator);
}
这段代码添加新方法,目的是为下面的测试做准备,请看测试用例:
@Test
public void testAllByFunction() throws Exception {
String exp = "r_exeAll(1,2,3)";
IExpressContext<String, Object> context = new DefaultContext<>();
runner.execute(exp, context, null, false, true);
}
这里进行了上面的方法调用,即进行了一次递归运算,测试结果如下:
测试通过!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)