/** * Produce an expression for this branch of the tree. * @return expression representing this branch */ @Override public String toString() { StringBuffer expr = new StringBuffer(); boolean needComma = false; for (Node child : getChildren()) { String subexpr = child.toString(); if (!"".equals(subexpr)) { if (child instanceof Or && this instanceof And) { subexpr = "(" + subexpr + ")"; } else if (child instanceof And && this instanceof Or) { subexpr = "(" + subexpr + ")"; } if (needComma) { expr.append(" " + getOperator() + " "); } needComma = true; expr.append(subexpr); } } return expr.toString(); }
/** * Produce an expression for this branch of the tree. * @return expression representing this branch */ @Override public String toString() { StringBuffer expr = new StringBuffer(); boolean needComma = false; for (Node child : getChildren()) { String subexpr = child.toString(); if (!"".equals(subexpr)) { if (child instanceof Or && this instanceof And) { subexpr = "(" + subexpr + ")"; } else if (child instanceof And && this instanceof Or) { subexpr = "(" + subexpr + ")"; } if (needComma) { expr.append(" " + getOperator() + " "); } needComma = true; expr.append(subexpr); } } return expr.toString(); }
/** * Produce an expression for this branch of the tree displaying only the children containing * the variable in input * @param variables The variables to display. * @return expression representing this branch */ public String getPartialString(List<String> variables) { StringBuffer expr = new StringBuffer(); boolean needComma = false; if (root instanceof Operator) { Set<Node> nodes = ((Operator) root).getChildren(); for (Node child : nodes) { String subexpr = child.toString(); if (!"".equals(subexpr) && isStringContainingAnyValueInArray(subexpr, variables)) { if (child instanceof Or && root instanceof And) { subexpr = "(" + subexpr + ")"; } else if (child instanceof And && root instanceof Or) { subexpr = "(" + subexpr + ")"; } if (needComma) { expr.append(" " + ((Operator) root).getOperator() + " "); } needComma = true; expr.append(subexpr); } } } return expr.toString(); }
for (LogicExpression.Node child : op.getChildren()) { createConstraintStructure(child, set, codeToConstraint);
for (LogicExpression.Node child : op.getChildren()) { createConstraintStructure(child, set, codeToConstraint);
/** * Produce an expression for this branch of the tree displaying only the children containing * the variable in input * @param variables The variables to display. * @return expression representing this branch */ public String getPartialString(List<String> variables) { StringBuffer expr = new StringBuffer(); boolean needComma = false; if (root instanceof Operator) { Set<Node> nodes = ((Operator) root).getChildren(); for (Node child : nodes) { String subexpr = child.toString(); if (!"".equals(subexpr) && isStringContainingAnyValueInArray(subexpr, variables)) { if (child instanceof Or && root instanceof And) { subexpr = "(" + subexpr + ")"; } else if (child instanceof And && root instanceof Or) { subexpr = "(" + subexpr + ")"; } if (needComma) { expr.append(" " + ((Operator) root).getOperator() + " "); } needComma = true; expr.append(subexpr); } } } return expr.toString(); }
/** * Remove any variables that aren't in the given set. * * @param variables Collection of variable names * @param node root of subtree */ private void removeAllVariablesExcept(Collection<String> variables, Operator node) { for (Node child : new ArrayList<Node>(node.getChildren())) { if (child instanceof Operator) { removeAllVariablesExcept(variables, (Operator) child); } else if (child instanceof Variable && !variables.contains(((Variable) child).getName())) { node.removeChild(child); } } }
/** * Remove any variables that aren't in the given set. * * @param variables Collection of variable names * @param node root of subtree */ private void removeAllVariablesExcept(Collection<String> variables, Operator node) { for (Node child : new ArrayList<Node>(node.getChildren())) { if (child instanceof Operator) { removeAllVariablesExcept(variables, (Operator) child); } else if (child instanceof Variable && !variables.contains(((Variable) child).getName())) { node.removeChild(child); } } }
/** * Remove a variable from a branch of the tree. * @param name variable name * @param node root of subtree */ private void removeVariable(String name, Operator node) { for (Node child : new ArrayList<Node>(node.getChildren())) { if (child instanceof Operator) { removeVariable(name, (Operator) child); } else if (child instanceof Variable && ((Variable) child).getName().equals(name)) { node.removeChild(child); } } }
private void getVariableNames(Set<String> variables, Node node) { if (node instanceof Operator) { for (Node child : ((Operator) node).getChildren()) { getVariableNames(variables, child); } } else { variables.add(((Variable) node).getName()); } }
/** * Remove a variable from a branch of the tree. * @param name variable name * @param node root of subtree */ private void removeVariable(String name, Operator node) { for (Node child : new ArrayList<Node>(node.getChildren())) { if (child instanceof Operator) { removeVariable(name, (Operator) child); } else if (child instanceof Variable && ((Variable) child).getName().equals(name)) { node.removeChild(child); } } }
private void getVariableNames(Set<String> variables, Node node) { if (node instanceof Operator) { for (Node child : ((Operator) node).getChildren()) { getVariableNames(variables, child); } } else { variables.add(((Variable) node).getName()); } }