dlmarion commented on code in PR #31:
URL: https://github.com/apache/accumulo-access/pull/31#discussion_r1463236987
##########
src/main/java/org/apache/accumulo/access/AccessExpression.java:
##########
@@ -59,47 +74,103 @@ public interface AccessExpression {
String getExpression();
/**
- * Deduplicate, sort, and flatten expressions.
- *
+ * @return the unique set of authorizations that occur in the expression.
For example, for the
+ * expression {@code (A&B)|(A&C)|(A&D)}, this method would return
{@code [A,B,C,D]}.
+ */
+ Authorizations getAuthorizations();
+
+ /**
+ * This is equivalent to calling {@code AccessExpression.of(expression,
false);}
+ */
+ static AccessExpression of(String expression) throws
IllegalAccessExpressionException {
+ return new AccessExpressionImpl(expression, false);
+ }
+
+ /**
* <p>
- * As an example of flattening, the expression {@code A&(B&C)} can be
flattened to {@code A&B&C}.
+ * Validates an access expression and creates an immutable AccessExpression
object.
*
* <p>
- * As an example of sorting, the expression {@code (Z&Y)|(C&B)} can be
sorted to
- * {@code (B&C)|(Y&Z)}
+ * When the {@code normalize} parameter is true, then will deduplicate,
sort, flatten, and remove
+ * unneeded parens in the expressions. Normalization is done in addition to
validation. The
+ * following list gives examples of what each normalization step does.
*
- * <p>
- * As an example of deduplication, the expression {@code X&Y&X} is
equivalent to {@code X&Y}
+ * <ul>
+ * <li>As an example of flattening, the expression {@code A&(B&C)} can be
flattened to
+ * {@code A&B&C}.</li>
+ * <li>As an example of sorting, the expression {@code (Z&Y)|(C&B)} can be
sorted to
+ * {@code (B&C)|(Y&Z)}</li>
+ * <li>As an example of deduplication, the expression {@code X&Y&X} is
equivalent to
+ * {@code X&Y}</li>
+ * <li>As an example of unneed parens, the expression {@code "ABC"&"XYZ"} is
equivalent to
Review Comment:
Did you mean to put parens here instead of quotes?
##########
src/main/java/org/apache/accumulo/access/AccessExpressionImpl.java:
##########
@@ -20,99 +20,77 @@
import static java.nio.charset.StandardCharsets.UTF_8;
-import java.util.Arrays;
import java.util.HashSet;
-import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Predicate;
class AccessExpressionImpl implements AccessExpression {
- private final byte[] expression;
+ public static final AccessExpression EMPTY = new AccessExpressionImpl("",
false);
- final AeNode aeNode;
+ private final String expression;
- private final AtomicReference<String> expressionString = new
AtomicReference<>(null);
-
- @Override
- public String getExpression() {
- var expStr = expressionString.get();
- if (expStr != null) {
- return expStr;
+ AccessExpressionImpl(String expression, boolean normalize) {
+ if (normalize) {
+ // validate and normalize expression
+ this.expression = normalize(expression);
+ } else {
+ validate(expression);
+ this.expression = expression;
}
-
- return expressionString.updateAndGet(es -> es == null ? new
String(expression, UTF_8) : es);
}
- // must create this after creating EMPTY_NODE
- static final AccessExpression EMPTY = new AccessExpressionImpl("");
+ AccessExpressionImpl(byte[] expression, boolean normalize) {
+ if (normalize) {
+ // validate and normalize expression
+ this.expression = normalize(expression);
+ } else {
+ validate(expression);
+ this.expression = new String(expression, UTF_8);
+ }
Review Comment:
Could replace with:
```suggestion
this(new String(expression, UTF_8), normalize);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]