@Override public Set<String> collectSources( Set<String> parentSources, Map<String, RoutingPolicy> routingPolicies, Warnings w) { return _expr.collectSources(parentSources, routingPolicies, w); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Not other = (Not) obj; if (_expr == null) { if (other._expr != null) { return false; } } else if (!_expr.equals(other._expr)) { return false; } return true; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((_expr == null) ? 0 : _expr.hashCode()); return result; }
boolean atLeastOneComplex = false; for (BooleanExpr conjunct : _conjuncts) { BooleanExpr simpleConjunct = conjunct.simplify(); if (simpleConjunct.equals(BooleanExprs.FALSE)) { atLeastOneFalse = true; if (!atLeastOneComplex) { simpleConjunctsBuilder.add(simpleConjunct); } else if (!simpleConjunct.equals(BooleanExprs.TRUE)) { atLeastOneComplex = true; simpleConjunctsBuilder.add(simpleConjunct);
@Override public Result evaluate(Environment environment) { Result result = _expr.evaluate(environment); if (!result.getExit()) { result.setBooleanValue(!result.getBooleanValue()); } return result; }
@Test public void simplifyTwoStatements() { Disjunction two = new Disjunction(ImmutableList.of(CALL_EXPR_CONTEXT, CALL_STATEMENT_CONTEXT)); BooleanExpr simplified = two.simplify(); assertThat(simplified, allOf(instanceOf(Disjunction.class), equalTo(two))); assertThat(simplified.simplify(), is(simplified)); }
@Override public String toString() { return toStringHelper().toString(); } }
String.format( "Unimplemented feature %s for %s transfer function on interface %s", expr.toString(), s, _graphEdge.toString());
@Override public List<Statement> simplify() { if (_simplified != null) { return _simplified; } ImmutableList.Builder<Statement> simpleTrueStatementsBuilder = ImmutableList.builder(); ImmutableList.Builder<Statement> simpleFalseStatementsBuilder = ImmutableList.builder(); BooleanExpr simpleGuard = _guard.simplify(); for (Statement trueStatement : _trueStatements) { simpleTrueStatementsBuilder.addAll(trueStatement.simplify()); } List<Statement> simpleTrueStatements = simpleTrueStatementsBuilder.build(); for (Statement falseStatement : _falseStatements) { simpleFalseStatementsBuilder.addAll(falseStatement.simplify()); } List<Statement> simpleFalseStatements = simpleFalseStatementsBuilder.build(); if (simpleGuard.equals(BooleanExprs.TRUE)) { _simplified = simpleTrueStatements; } else if (simpleGuard.equals(BooleanExprs.FALSE)) { _simplified = simpleFalseStatements; } else if (simpleTrueStatements.isEmpty() && simpleFalseStatements.isEmpty()) { _simplified = Collections.emptyList(); } else { If simple = new If(getComment(), simpleGuard, simpleTrueStatements, simpleFalseStatements); _simplified = ImmutableList.of(simple); simple._simplified = _simplified; } return _simplified; } }
@Override public Result evaluate(Environment environment) { for (Statement statement : _preStatements) { statement.execute(environment); } Result result = _expr.evaluate(environment); for (Statement statement : _postStatements) { statement.execute(environment); } if (result.getBooleanValue()) { for (Statement statement : _postTrueStatements) { statement.execute(environment); } } return result; }
@Override public Set<String> collectSources( Set<String> parentSources, Map<String, RoutingPolicy> routingPolicies, Warnings w) { ImmutableSet.Builder<String> childSources = ImmutableSet.builder(); for (BooleanExpr disjunct : _subroutines) { childSources.addAll(disjunct.collectSources(parentSources, routingPolicies, w)); } return childSources.build(); }
@Override public Result evaluate(Environment environment) { for (BooleanExpr conjunct : _conjuncts) { Result conjunctResult = conjunct.evaluate(environment); if (conjunctResult.getExit()) { return conjunctResult; } else if (!conjunctResult.getBooleanValue()) { conjunctResult.setReturn(false); return conjunctResult; } } Result result = new Result(); result.setBooleanValue(true); return result; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((_falseStatements == null) ? 0 : _falseStatements.hashCode()); result = prime * result + ((_guard == null) ? 0 : _guard.hashCode()); result = prime * result + ((_trueStatements == null) ? 0 : _trueStatements.hashCode()); return result; }
@Override public Set<String> collectSources( Set<String> parentSources, Map<String, RoutingPolicy> routingPolicies, Warnings w) { ImmutableSet.Builder<String> childSources = ImmutableSet.builder(); for (BooleanExpr conjunct : _subroutines) { childSources.addAll(conjunct.collectSources(parentSources, routingPolicies, w)); } return childSources.build(); }
@Override public Result evaluate(Environment environment) { for (BooleanExpr disjunct : _disjuncts) { Result disjunctResult = disjunct.evaluate(environment); if (disjunctResult.getExit()) { return disjunctResult; } else if (disjunctResult.getBooleanValue()) { disjunctResult.setReturn(false); return disjunctResult; } } Result result = new Result(); result.setBooleanValue(false); return result; }
@Override public Set<String> collectSources( Set<String> parentSources, Map<String, RoutingPolicy> routingPolicies, Warnings w) { ImmutableSet.Builder<String> childSources = ImmutableSet.builder(); for (BooleanExpr conjunct : _conjuncts) { childSources.addAll(conjunct.collectSources(parentSources, routingPolicies, w)); } return childSources.build(); }
@Override public Result execute(Environment environment) { Result exprResult = _guard.evaluate(environment); if (exprResult.getExit()) { return exprResult; } boolean guardVal = exprResult.getBooleanValue(); List<Statement> toExecute = guardVal ? _trueStatements : _falseStatements; for (Statement statement : toExecute) { Result result = statement.execute(environment); if (result.getExit() || result.getReturn()) { return result; } } Result fallThroughResult = new Result(); fallThroughResult.setFallThrough(true); return fallThroughResult; }
@Override public Set<String> collectSources( Set<String> parentSources, Map<String, RoutingPolicy> routingPolicies, Warnings w) { ImmutableSet.Builder<String> childSources = ImmutableSet.builder(); for (BooleanExpr disjunct : _disjuncts) { childSources.addAll(disjunct.collectSources(parentSources, routingPolicies, w)); } return childSources.build(); }
@Override public Result evaluate(Environment environment) { Result subroutineResult = new Result(); // By default move on to the next policy subroutineResult.setFallThrough(true); for (BooleanExpr subroutine : _subroutines) { subroutineResult = subroutine.evaluate(environment); if (subroutineResult.getExit()) { // Reached an exit/terminal action. Return regardless of boolean value return subroutineResult; } else if (!subroutineResult.getFallThrough() && !subroutineResult.getBooleanValue()) { // Found first match that returns false, short-circuit here subroutineResult.setReturn(false); return subroutineResult; } } // Check if we are allowed to fall through to the default policy, if not, return last result if (!subroutineResult.getFallThrough()) { return subroutineResult; } else { String defaultPolicy = environment.getDefaultPolicy(); if (defaultPolicy != null) { CallExpr callDefaultPolicy = new CallExpr(environment.getDefaultPolicy()); return callDefaultPolicy.evaluate(environment); } else { throw new BatfishException("Default policy is not set"); } } }