/** * 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 void stringify(Node root, byte[] expression, StringBuilder out) { if (root.type == NodeType.TERM) { out.append(new String(expression, root.start, root.end - root.start, Constants.UTF8)); } else { String sep = ""; for (Node c : root.children) { out.append(sep); boolean parens = (c.type != NodeType.TERM && root.type != c.type); if (parens) out.append("("); stringify(c, expression, out); if (parens) out.append(")"); sep = root.type == NodeType.AND ? "&" : "|"; } } }
/** * 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 void stringify(Node root, byte[] expression, StringBuilder out) { if (root.type == NodeType.TERM) { out.append(new String(expression, root.start, root.end - root.start, Constants.UTF8)); } else { String sep = ""; for (Node c : root.children) { out.append(sep); boolean parens = (c.type != NodeType.TERM && root.type != c.type); if (parens) out.append("("); stringify(c, expression, out); if (parens) out.append(")"); sep = root.type == NodeType.AND ? "&" : "|"; } } }