org.mozilla.zest.core.v1.ZestConditional类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中org.mozilla.zest.core.v1.ZestConditional类的一些代码示例,展示了ZestConditional类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZestConditional类的具体详情如下:
包路径:org.mozilla.zest.core.v1.ZestConditional
类名称:ZestConditional

ZestConditional介绍

[英]The Class ZestConditional.
[中]这门课是有条件的。

代码示例

代码示例来源:origin: mozilla/zest

@Override
public ZestStatement deepCopy() {
  ZestConditional copy = new ZestConditional(getIndex());
  if (this.rootExpression != null) {
    copy.rootExpression = rootExpression.deepCopy();
  }
  for (ZestStatement stmt : ifStatements) {
    copy.ifStatements.add(stmt.deepCopy());
  }
  for (ZestStatement stmt : elseStatements) {
    copy.elseStatements.add(stmt.deepCopy());
  }
  copy.setEnabled(this.isEnabled());
  return copy;
}

代码示例来源:origin: mozilla/zest

@Override
public void move(int index, ZestStatement stmt) {
  if (this.ifStatements.contains(stmt)) {
    this.removeIf(stmt);
    this.addIf(index, stmt);
  } else if (this.elseStatements.contains(stmt)) {
    this.removeElse(stmt);
    this.addElse(index, stmt);
  } else {
    throw new IllegalArgumentException("Not a direct child: " + stmt);
  }
}

代码示例来源:origin: mozilla/zest

@Override
public List<ZestStatement> getChildren() {
  List<ZestStatement> children = new ArrayList<ZestStatement>();
  children.addAll(this.getIfStatements());
  children.addAll(this.getElseStatements());
  return Collections.unmodifiableList(children);
}

代码示例来源:origin: mozilla/zest

/**
 * Moves an else.
 *
 * @param index the destination of the else statement
 * @param req the else statement to move
 */
public void moveElse(int index, ZestStatement req) {
  this.removeElse(req);
  this.addElse(index, req);
}

代码示例来源:origin: mozilla/zest

/**
 * Moves if.
 *
 * @param index the new index
 * @param req the statement to move
 */
public void moveIf(int index, ZestStatement req) {
  this.removeIf(req);
  this.addIf(index, req);
}

代码示例来源:origin: mozilla/zest

/**
 * Method testRemoveMiddleElse.
 *
 * @throws Exception
 */
@Test
public void testRemoveMiddleElse() throws Exception {
  ZestConditional zc = new ZestConditional(new ZestExpressionRegex("BODY", ""));
  ZestRequest req1 = new ZestRequest();
  ZestRequest req2 = new ZestRequest();
  ZestRequest req3 = new ZestRequest();
  zc.addElse(req1);
  zc.addElse(req2);
  zc.addElse(req3);
  zc.removeElse(req2);
  checkOrder(new ZestStatement[] {zc, req1, req3, null});
}

代码示例来源:origin: mozilla/zest

/**
 * Method testRemoveMiddleIf.
 *
 * @throws Exception
 */
@Test
public void testRemoveMiddleIf() throws Exception {
  ZestConditional zc = new ZestConditional(new ZestExpressionRegex("BODY", ""));
  ZestRequest req1 = new ZestRequest();
  ZestRequest req2 = new ZestRequest();
  ZestRequest req3 = new ZestRequest();
  zc.addIf(req1);
  zc.addIf(req2);
  zc.addIf(req3);
  zc.removeIf(req2);
  checkOrder(new ZestStatement[] {zc, req1, req3, null});
}

代码示例来源:origin: mozilla/zest

/**
 * Method testMoveLastElse.
 *
 * @throws Exception
 */
@Test
public void testMoveLastElse() throws Exception {
  ZestConditional zc = new ZestConditional(new ZestExpressionRegex("BODY", ""));
  ZestRequest req1 = new ZestRequest();
  ZestRequest req2 = new ZestRequest();
  ZestRequest req3 = new ZestRequest();
  zc.addElse(req1);
  zc.addElse(req2);
  zc.addElse(req3);
  zc.moveElse(0, req3);
  checkOrder(new ZestStatement[] {zc, req3, req1, req2, null});
}

代码示例来源:origin: mozilla/zest

/**
 * Method testMoveFirstIf.
 *
 * @throws Exception
 */
@Test
public void testMoveFirstIf() throws Exception {
  ZestConditional zc = new ZestConditional(new ZestExpressionRegex("BODY", ""));
  ZestRequest req1 = new ZestRequest();
  ZestRequest req2 = new ZestRequest();
  ZestRequest req3 = new ZestRequest();
  zc.addIf(req1);
  zc.addIf(req2);
  zc.addIf(req3);
  zc.moveIf(2, req1);
  checkOrder(new ZestStatement[] {zc, req2, req3, req1, null});
}

代码示例来源:origin: mozilla/zest

ZestConditional zc1 = new ZestConditional(new ZestExpressionRegex("BODY", ""));
ZestConditional zc2 = new ZestConditional(new ZestExpressionRegex("BODY", ""));
ZestConditional zc3 = new ZestConditional(new ZestExpressionRegex("BODY", ""));
ZestConditional zc4 = new ZestConditional(new ZestExpressionRegex("BODY", ""));
ZestRequest req1 = new ZestRequest();
ZestRequest req2 = new ZestRequest();
zc1.addIf(req1);
checkOrder(new ZestStatement[] {zc1, req1, null});
zc1.addIf(zc2);
checkOrder(new ZestStatement[] {zc1, req1, zc2, null});
zc2.addIf(req2);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, null});
zc2.addElse(req3);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, req3, null});
zc2.addElse(zc3);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, req3, zc3, null});
zc3.addElse(req4);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, req3, zc3, req4, null});
zc2.addElse(req5);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, req3, zc3, req4, req5, null});
zc2.addElse(zc4);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, req3, zc3, req4, req5, zc4, null});
zc4.addElse(req6);
checkOrder(
    new ZestStatement[] {zc1, req1, zc2, req2, req3, zc3, req4, req5, zc4, req6, null});
zc1.removeElse(zc3);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, req3, req5, zc4, req6, null});

代码示例来源:origin: mozilla/zest

/**
 * Method testDeepConditionals1.
 *
 * @throws Exception
 */
@Test
public void testDeepConditionals1() throws Exception {
  ZestConditional zc1 = new ZestConditional(new ZestExpressionRegex("BODY", ""));
  ZestConditional zc2 = new ZestConditional(new ZestExpressionRegex("BODY", ""));
  ZestRequest req1 = new ZestRequest();
  ZestRequest req2 = new ZestRequest();
  zc1.addIf(zc2);
  zc2.addIf(req1);
  zc1.addElse(req2);
  checkOrder(new ZestStatement[] {zc1, zc2, req1, req2, null});
}

代码示例来源:origin: mozilla/zest

ZestConditional zc1 = new ZestConditional(new ZestExpressionRegex("BODY", ""));
ZestConditional zc2 = new ZestConditional(new ZestExpressionRegex("BODY", ""));
ZestConditional zc3 = new ZestConditional(new ZestExpressionRegex("BODY", ""));
ZestConditional zc4 = new ZestConditional(new ZestExpressionRegex("BODY", ""));
ZestRequest req1 = new ZestRequest();
ZestRequest req2 = new ZestRequest();
zc1.addIf(req1);
checkOrder(new ZestStatement[] {zc1, req1, null});
zc1.addIf(zc2);
checkOrder(new ZestStatement[] {zc1, req1, zc2, null});
zc2.addIf(req2);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, null});
xfrm1.setFieldDefinition(new ZestFieldDefinition(1, "xxx"));
zc2.addElse(req3);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, req3, null});
zc2.addElse(zc3);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, req3, zc3, null});
zc3.addElse(req4);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, req3, zc3, req4, null});
zc2.addElse(req5);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, req3, zc3, req4, req5, null});
zc2.addElse(zc4);
checkOrder(new ZestStatement[] {zc1, req1, zc2, req2, req3, zc3, req4, req5, zc4, null});
zc4.addElse(req6);
xfrm2.setFieldDefinition(new ZestFieldDefinition(1, "xxx"));
zc1.removeIf(req3);

代码示例来源:origin: mozilla/zest

/**
 * Method testAddingIfs.
 *
 * @throws Exception
 */
@Test
public void testAddingIfs() throws Exception {
  ZestConditional zc = new ZestConditional(new ZestExpressionRegex("BODY", ""));
  ZestRequest req = new ZestRequest();
  zc.addIf(req);
  assertEquals(1, req.getIndex());
  checkOrder(new ZestStatement[] {zc, req, null});
  ZestRequest req2 = new ZestRequest();
  zc.addIf(req2);
  // 0: zc
  // 1:   req
  // 2:   req2
  checkOrder(new ZestStatement[] {zc, req, req2, null});
  ZestRequest req3 = new ZestRequest();
  zc.addIf(1, req3);
  // 0: zc
  // 1:   req
  // 2:   req3
  // 3:   req2
  checkOrder(new ZestStatement[] {zc, req, req3, req2, null});
}

代码示例来源:origin: mozilla/zest

/**
 * Method testAddingElses.
 *
 * @throws Exception
 */
@Test
public void testAddingElses() throws Exception {
  ZestConditional zc = new ZestConditional(new ZestExpressionRegex("BODY", ""));
  ZestRequest req = new ZestRequest();
  zc.addElse(req);
  assertEquals(1, req.getIndex());
  checkOrder(new ZestStatement[] {zc, req, null});
  ZestRequest req2 = new ZestRequest();
  zc.addElse(req2);
  // 0: zc
  // 1:   req
  // 2:   req2
  checkOrder(new ZestStatement[] {zc, req, req2, null});
  ZestRequest req3 = new ZestRequest();
  zc.addElse(1, req3);
  // 0: zc
  // 1:   req
  // 2:   req3
  // 3:   req2
  checkOrder(new ZestStatement[] {zc, req, req3, req2, null});
}

代码示例来源:origin: mozilla/zest

@Test
public void testGetLast() {
  ZestLoopString loop = new ZestLoopString(values);
  for (int i = 0; i < 10; i++) {
    loop.addStatement(new ZestConditional());
  }
  loop.addStatement(new ZestLoopString(values));
  assertTrue(loop.getLast().getClass().equals(ZestLoopString.class));
}

代码示例来源:origin: mozilla/zest

if (zc.isTrue(this)) {
  this.debug(stmt.getIndex() + " Conditional TRUE: " + zc.getClass().getName());
  for (ZestStatement ifStmt : zc.getIfStatements()) {
    lastResponse = this.runStatement(script, ifStmt, lastResponse);
  for (ZestStatement elseStmt : zc.getElseStatements()) {
    lastResponse = this.runStatement(script, elseStmt, lastResponse);

代码示例来源:origin: mozilla/zest

and.addChildCondition(url);
  or.addChildCondition(and);
  ZestConditional cond = new ZestConditional(or);
  assertTrue(cond.isTrue(new TestRuntime(resp)));
} catch (MalformedURLException e) {
  e.printStackTrace();

代码示例来源:origin: mozilla/zest

printIndent(indent, stmt.getIndex());
System.out.print("IF ");
printExpression(zc.getRootExpression(), 0);
System.out.println();
for (ZestStatement ifStmt : zc.getIfStatements()) {
  list(ifStmt, indent + 1);
for (ZestStatement elseStmt : zc.getElseStatements()) {
  list(elseStmt, indent + 1);

代码示例来源:origin: mozilla/zest

/**
 * Adds an else.
 *
 * @param req the statement to add as else
 */
public void addElse(ZestStatement req) {
  this.addElse(this.elseStatements.size(), req);
}

代码示例来源:origin: mozilla/zest

/**
 * Adds an if statement.
 *
 * @param req the Statement to add as If
 */
public void addIf(ZestStatement req) {
  this.addIf(this.ifStatements.size(), req);
}

相关文章