Node processTerm(int start, int end, Node expr, byte[] expression) { if (start != end) { if (expr != null) throw new BadArgumentException("expression needs | or &", new String(expression, Constants.UTF8), start); return new Node(start, end); } if (expr == null) throw new BadArgumentException("empty term", new String(expression, Constants.UTF8), start); return expr; }
throw new BadArgumentException("cannot mix & and |", new String(expression, Constants.UTF8), index - 1); } else { result = new Node(NodeType.AND, wholeTermStart); result.add(expr); expr = null; subtermStart = index; throw new BadArgumentException("cannot mix | and &", new String(expression, Constants.UTF8), index - 1); } else { result = new Node(NodeType.OR, wholeTermStart); result.add(expr); expr = null; subtermStart = index; if (result.type == child.type) for (Node c : child.children) result.add(c); else result.add(child); result.end = index - 1; return result; result.add(child); result.end = index; } else
throw new BadArgumentException("cannot mix & and |", new String(expression, Constants.UTF8), index - 1); } else { result = new Node(NodeType.AND, wholeTermStart); result.add(expr); expr = null; subtermStart = index; throw new BadArgumentException("cannot mix | and &", new String(expression, Constants.UTF8), index - 1); } else { result = new Node(NodeType.OR, wholeTermStart); result.add(expr); expr = null; subtermStart = index; if (result.type == child.type) for (Node c : child.children) result.add(c); else result.add(child); result.end = index - 1; return result; result.add(child); result.end = index; } else
private final boolean evaluate(final byte[] expression, final ColumnVisibility.Node root) throws VisibilityParseException { if (expression.length == 0) return true; switch (root.type) { case TERM: return auths.contains(root.getTerm(expression)); case AND: if (root.children == null || root.children.size() < 2) throw new VisibilityParseException("AND has less than 2 children", expression, root.start); for (ColumnVisibility.Node child : root.children) { if (!evaluate(expression, child)) return false; } return true; case OR: if (root.children == null || root.children.size() < 2) throw new VisibilityParseException("OR has less than 2 children", expression, root.start); for (ColumnVisibility.Node child : root.children) { if (evaluate(expression, child)) return true; } return false; default: throw new VisibilityParseException("No such node type", expression, root.start); } } }
private final boolean evaluate(final byte[] expression, final ColumnVisibility.Node root) throws VisibilityParseException { if (expression.length == 0) return true; switch (root.type) { case TERM: return auths.contains(root.getTerm(expression)); case AND: if (root.children == null || root.children.size() < 2) throw new VisibilityParseException("AND has less than 2 children", expression, root.start); for (ColumnVisibility.Node child : root.children) { if (!evaluate(expression, child)) return false; } return true; case OR: if (root.children == null || root.children.size() < 2) throw new VisibilityParseException("OR has less than 2 children", expression, root.start); for (ColumnVisibility.Node child : root.children) { if (evaluate(expression, child)) return true; } return false; default: throw new VisibilityParseException("No such node type", expression, root.start); } } }
Node processTerm(int start, int end, Node expr, byte[] expression) { if (start != end) { if (expr != null) throw new BadArgumentException("expression needs | or &", new String(expression, Constants.UTF8), start); return new Node(start, end); } if (expr == null) throw new BadArgumentException("empty term", new String(expression, Constants.UTF8), start); return expr; }