protected WritableComparator(Class<? extends WritableComparable> keyClass, boolean createInstances) { this.keyClass = keyClass; if (createInstances) { key1 = newKey(); key2 = newKey(); buffer = new DataInputBuffer(); } else { key1 = key2 = null; buffer = null; } }
/** * Evaluates the given column visibility against the authorizations provided to this evaluator. * A visibility passes evaluation if all authorizations in it are contained in those known to the evaluator, and * all AND and OR subexpressions have at least two children. * * @param visibility column visibility to evaluate * @return true if visibility passes evaluation * @throws VisibilityParseException if an AND or OR subexpression has less than two children, or a subexpression is of an unknown type */ public boolean evaluate(ColumnVisibility visibility) throws VisibilityParseException { // The VisibilityEvaluator computes a trie from the given Authorizations, that ColumnVisibility expressions can be evaluated against. return evaluate(visibility.getExpression(), visibility.getParseTree()); }
/** * Compares this byte sequence to another. * * @param obs byte sequence to compare * @return comparison result * @see #compareBytes(ByteSequence, ByteSequence) */ public int compareTo(ByteSequence obs) { if (isBackedByArray() && obs.isBackedByArray()) { return WritableComparator.compareBytes(getBackingArray(), offset(), length(), obs.getBackingArray(), obs.offset(), obs.length()); } return compareBytes(this, obs); }
public static boolean canRead(String visibility, String[] authorizations) { VisibilityEvaluator visibilityEvaluator = new VisibilityEvaluator(new Authorizations(authorizations)); ColumnVisibility columnVisibility = new ColumnVisibility(visibility); try { return visibilityEvaluator.evaluate(columnVisibility); } catch (VisibilityParseException ex) { throw new RuntimeException("could not evaluate visibility " + visibility, ex); } } }
public static Node normalize(Node root, byte[] expression) { return normalize(root, expression, new NodeComparator(expression)); }
private void validate(byte[] expression) { if (expression != null && expression.length > 0) { ColumnVisibilityParser p = new ColumnVisibilityParser(); node = p.parse(expression); } else { node = EMPTY_NODE; } this.expression = expression; }
/** * Resets the data that the buffer reads. */ public void reset(byte[] input, int length) { buffer.reset(input, 0, length); }
/** * Compute hash for binary data. */ public static int hashBytes(byte[] bytes, int length) { return hashBytes(bytes, 0, length); }
/** * Creates a column visibility for a Mutation from a string already encoded in UTF-8 bytes. * * @param expression visibility expression, encoded as UTF-8 bytes * @see #ColumnVisibility(String) */ public ColumnVisibility(byte[] expression) { validate(expression); }
/** * Returns the current position in the input. */ public int getPosition() { return buffer.getPosition(); }
/** * Lexicographic order of binary data. */ public static int compareBytes(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { return FastByteComparisons.compareTo(b1, s1, l1, b2, s2, l2); }
/** * Returns the length of the input. */ public int getLength() { return buffer.getLength(); }
/** * Creates a new evaluator for the given collection of authorizations. * Each authorization string is escaped before handling, and the original * strings are unchanged. * * @param authorizations authorizations object */ public VisibilityEvaluator(Authorizations authorizations) { this.auths = escape((Authorizations) authorizations); }
public static boolean canRead(String visibility, String[] authorizations) { if (visibility == null) { throw new RuntimeException("visibility cannot be null"); } VisibilityEvaluator visibilityEvaluator = new VisibilityEvaluator(new Authorizations(authorizations)); ColumnVisibility columnVisibility = new ColumnVisibility(visibility); try { return visibilityEvaluator.evaluate(columnVisibility); } catch (VisibilityParseException ex) { throw new RuntimeException("could not evaluate visibility " + visibility, ex); } } }
/** * Evaluates the given column visibility against the authorizations provided to this evaluator. * A visibility passes evaluation if all authorizations in it are contained in those known to the evaluator, and * all AND and OR subexpressions have at least two children. * * @param visibility column visibility to evaluate * @return true if visibility passes evaluation * @throws VisibilityParseException if an AND or OR subexpression has less than two children, or a subexpression is of an unknown type */ public boolean evaluate(ColumnVisibility visibility) throws VisibilityParseException { // The VisibilityEvaluator computes a trie from the given Authorizations, that ColumnVisibility expressions can be evaluated against. return evaluate(visibility.getExpression(), visibility.getParseTree()); }
/** * Compares this byte sequence to another. * * @param obs byte sequence to compare * @return comparison result * @see #compareBytes(ByteSequence, ByteSequence) */ public int compareTo(ByteSequence obs) { if (isBackedByArray() && obs.isBackedByArray()) { return WritableComparator.compareBytes(getBackingArray(), offset(), length(), obs.getBackingArray(), obs.offset(), obs.length()); } return compareBytes(this, obs); }
protected WritableComparator(Class<? extends WritableComparable> keyClass, boolean createInstances) { this.keyClass = keyClass; if (createInstances) { key1 = newKey(); key2 = newKey(); buffer = new DataInputBuffer(); } else { key1 = key2 = null; buffer = null; } }
public static Node normalize(Node root, byte[] expression) { return normalize(root, expression, new NodeComparator(expression)); }
/** * Resets the data that the buffer reads. */ public void reset(byte[] input, int start, int length) { buffer.reset(input, start, length); }