本文整理了Java中org.mozilla.zest.core.v1.ZestExpressionOr
类的一些代码示例,展示了ZestExpressionOr
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZestExpressionOr
类的具体详情如下:
包路径:org.mozilla.zest.core.v1.ZestExpressionOr
类名称:ZestExpressionOr
[英]The Class ZestExpressionOr.
[中]ZestExpressionOr类。
代码示例来源:origin: mozilla/zest
@Override
public ZestExpressionOr deepCopy() {
List<ZestExpressionElement> copyChildren = new LinkedList<>();
if (getChildrenCondition() != null) {
for (int i = 0; i < getChildrenCondition().size(); i++) {
copyChildren.add(getChildrenCondition().get(i).deepCopy());
}
}
ZestExpressionOr copy = new ZestExpressionOr(copyChildren);
copy.setInverse(isInverse());
return copy;
}
代码示例来源:origin: mozilla/zest
@Override
public String toString() {
if (this.getChildrenCondition() == null || this.getChildrenCondition().isEmpty()) {
return "Empty OR";
}
StringBuilder expression = new StringBuilder(150);
if (isInverse()) {
expression.append("NOT ");
}
expression.append('(');
int i = 0;
for (; i < this.getChildrenCondition().size() - 1; i++) {
expression.append(this.getChild(i).toString()).append(" OR ");
}
expression.append(this.getChild(i).toString()).append(')');
return expression.toString();
}
}
代码示例来源:origin: mozilla/zest
public void testOrDeepCopySingleAndSameChildrenSize() {
ZestExpressionOr or = new ZestExpressionOr();
or.addChildCondition(new ZestExpressionStatusCode(100));
or.addChildCondition(new ZestExpressionLength("response.body", 1, 1));
ZestExpressionOr copy = or.deepCopy();
assertTrue(or.getChildrenCondition().size() == copy.getChildrenCondition().size());
}
代码示例来源:origin: mozilla/zest
@Test
public void testOrDeepCopySingleAndSameChildrenClasses() {
List<ZestExpressionElement> children = new LinkedList<>();
for (int i = 0; i < 10; i++) {
children.add(new ZestExpressionLength());
}
ZestExpressionOr or = new ZestExpressionOr(children);
ZestExpressionOr copy = or.deepCopy();
for (int i = 0; i < children.size(); i++) {
assertTrue(or.getChild(i).getClass() == copy.getChild(i).getClass());
}
}
代码示例来源:origin: mozilla/zest
@Test
public void testZestExpressionOrLazyEvaluation() {
ZestExpressionOr or = new ZestExpressionOr();
ZestExpressionLength lengthExpr = new ZestExpressionLength("response.body", 100, 100);
ZestExpression expectedException =
new ZestExpression() {
@Override
public boolean isTrue(ZestRuntime runtime) {
throw new IllegalAccessError(
"This has not to be thrown cause of the Lazy evaluation!");
}
@Override
public ZestExpression deepCopy() {
return null;
}
};
or.addChildCondition(lengthExpr);
or.addChildCondition(expectedException);
ZestResponse response = new ZestResponse(null, "", "", 200, 100);
assertTrue(or.evaluate(new TestRuntime(response)));
}
}
代码示例来源:origin: mozilla/zest
System.out.print("OR: (");
for (lastChildPrinted = 0;
lastChildPrinted < orElement.getChildrenCondition().size() - 1;
lastChildPrinted++) {
printExpression(orElement.getChild(lastChildPrinted), indent + 1);
System.out.print(" || ");
printExpression(orElement.getChild(lastChildPrinted), indent + 1);
代码示例来源:origin: mozilla/zest
@Test
public void testOrDeepCopyNullChildren() {
ZestExpressionOr or = new ZestExpressionOr(null);
ZestExpressionOr copy = or.deepCopy();
assertTrue(copy.getClass().equals(or.getClass()));
}
代码示例来源:origin: mozilla/zest
System.out.println("ZestComplexExpression");
System.out.println("---------------------");
ZestExpressionOr or = new ZestExpressionOr();
or.addChildCondition(new ZestExpressionLength("response.body", 10, 20));
or.addChildCondition(new ZestExpressionStatusCode(200));
ZestExpressionAnd and = new ZestExpressionAnd();
and.addChildCondition(new ZestExpressionLength("response.body", 100, 200));
代码示例来源:origin: mozilla/zest
@Override
public boolean isTrue(ZestRuntime runtime) {
boolean toReturn = false;
for (ZestExpressionElement con : getChildrenCondition()) {
toReturn = toReturn || con.evaluate(runtime); // compute OR for each
// child
if (toReturn) {
break; // lazy evaluation
}
}
return toReturn;
}
代码示例来源:origin: mozilla/zest
@Test
public void testClearChildren() {
ZestExpressionAnd and = new ZestExpressionAnd();
LinkedList<ZestExpressionElement> children = new LinkedList<>();
children.add(new ZestExpressionAnd());
children.add(new ZestExpressionLength());
children.add(new ZestExpressionOr());
ZestExpressionOr or = new ZestExpressionOr(children);
and.setChildrenCondition(children);
and.addChildCondition(or);
and.clearChildren();
assertTrue(and.getChildrenCondition().isEmpty());
}
代码示例来源:origin: mozilla/zest
@Test
public void testDeepCopyOr() {
ZestExpressionOr or = new ZestExpressionOr();
ZestExpressionOr copy = or.deepCopy();
assertTrue(or.getClass().equals(copy.getClass()));
}
代码示例来源:origin: mozilla/zest
@Test
public void testComplexCondition() {
ZestExpressionAnd and = new ZestExpressionAnd();
ZestExpressionOr or = new ZestExpressionOr();
try {
ZestResponse resp =
or.addChildCondition(genericExp);
and.addChildCondition(length);
and.addChildCondition(code);
and.addChildCondition(time);
and.addChildCondition(url);
or.addChildCondition(and);
ZestConditional cond = new ZestConditional(or);
assertTrue(cond.isTrue(new TestRuntime(resp)));
内容来源于网络,如有侵权,请联系作者删除!