/** * 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); } } }
/** * 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); } } }
/** * Remove a variable from the expression. * @param name variable to remove */ public void removeVariable(String name) { if (root instanceof Operator) { removeVariable(name, (Operator) root); } else if (root instanceof Variable && ((Variable) root).getName().equals(name)) { throw new IllegalArgumentException("Removing root node"); } String logic = toString(); root = parse(logic); }
Map<String, Constraint> codeToConstraint) { if (node instanceof LogicExpression.Variable) { Constraint con = codeToConstraint.get(((LogicExpression.Variable) node).getName()); if (con != null) {
Map<String, Constraint> codeToConstraint) { if (node instanceof LogicExpression.Variable) { Constraint con = codeToConstraint.get(((LogicExpression.Variable) node).getName()); if (con != null) {
/** * 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); } } }
/** * Finds all the codes in a constraint logic that are ANDed in the given constraint logic. * * @param codes codes are added to this * @param node a node to traverse */ protected static void findAndCodes(Set<String> codes, LogicExpression.Node node) { if (node instanceof LogicExpression.Variable) { codes.add(((LogicExpression.Variable) node).getName()); } else if (node instanceof LogicExpression.And) { for (LogicExpression.Node child : ((LogicExpression.And) node).getChildren()) { findAndCodes(codes, child); } } }
/** * Finds all the codes in a constraint logic that are ANDed in the given constraint logic. * * @param codes codes are added to this * @param node a node to traverse */ protected static void findAndCodes(Set<String> codes, LogicExpression.Node node) { if (node instanceof LogicExpression.Variable) { codes.add(((LogicExpression.Variable) node).getName()); } else if (node instanceof LogicExpression.And) { for (LogicExpression.Node child : ((LogicExpression.And) node).getChildren()) { findAndCodes(codes, child); } } }
/** * Remove any variables that aren't in the given set. * @param variables Collection of variable names */ public void removeAllVariablesExcept(Collection<String> variables) { if (root instanceof Operator) { removeAllVariablesExcept(variables, (Operator) root); } else if (root instanceof Variable && !variables.contains(((Variable) root).getName())) { throw new IllegalArgumentException("Removing root node"); } String logic = toString(); root = parse(logic); }
/** * Remove any variables that aren't in the given set. * @param variables Collection of variable names */ public void removeAllVariablesExcept(Collection<String> variables) { if (root instanceof Operator) { removeAllVariablesExcept(variables, (Operator) root); } else if (root instanceof Variable && !variables.contains(((Variable) root).getName())) { throw new IllegalArgumentException("Removing root node"); } String logic = toString(); root = parse(logic); }
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()); } }
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 the expression. * @param name variable to remove */ public void removeVariable(String name) { if (root instanceof Operator) { removeVariable(name, (Operator) root); } else if (root instanceof Variable && ((Variable) root).getName().equals(name)) { throw new IllegalArgumentException("Removing root node"); } String logic = toString(); root = parse(logic); }
/** * Just returns the variable name. * @return string representation of this node */ @Override public String toString() { return getName(); } }
/** * Just returns the variable name. * @return string representation of this node */ @Override public String toString() { return getName(); } }