/** * Generates a byte[] that represents a normalized, but logically equivalent, form of this evaluator's expression. * * @return normalized expression in byte[] form */ public byte[] flatten() { Node normRoot = normalize(node, expression); StringBuilder builder = new StringBuilder(expression.length); stringify(normRoot, expression, builder); return builder.toString().getBytes(Constants.UTF8); }
/** * Generates a byte[] that represents a normalized, but logically equivalent, form of this evaluator's expression. * * @return normalized expression in byte[] form */ public byte[] flatten() { Node normRoot = normalize(node, expression); StringBuilder builder = new StringBuilder(expression.length); stringify(normRoot, expression, builder); return builder.toString().getBytes(Constants.UTF8); }
public static Node normalize(Node root, byte[] expression) { return normalize(root, expression, new NodeComparator(expression)); }
public static Node normalize(Node root, byte[] expression) { return normalize(root, expression, new NodeComparator(expression)); }
public static Node normalize(Node root, byte[] expression, NodeComparator comparator) { if (root.type != NodeType.TERM) { TreeSet<Node> rolledUp = new TreeSet<Node>(comparator); java.util.Iterator<Node> itr = root.children.iterator(); while (itr.hasNext()) { Node c = normalize(itr.next(), expression, comparator); if (c.type == root.type) { rolledUp.addAll(c.children); itr.remove(); } } rolledUp.addAll(root.children); root.children.clear(); root.children.addAll(rolledUp); // need to promote a child if it's an only child if (root.children.size() == 1) { return root.children.get(0); } } return root; }
public static Node normalize(Node root, byte[] expression, NodeComparator comparator) { if (root.type != NodeType.TERM) { TreeSet<Node> rolledUp = new TreeSet<Node>(comparator); java.util.Iterator<Node> itr = root.children.iterator(); while (itr.hasNext()) { Node c = normalize(itr.next(), expression, comparator); if (c.type == root.type) { rolledUp.addAll(c.children); itr.remove(); } } rolledUp.addAll(root.children); root.children.clear(); root.children.addAll(rolledUp); // need to promote a child if it's an only child if (root.children.size() == 1) { return root.children.get(0); } } return root; }