keith-turner commented on code in PR #83:
URL: https://github.com/apache/accumulo-access/pull/83#discussion_r1939923556


##########
src/main/java/org/apache/accumulo/access/AccessExpression.java:
##########
@@ -87,109 +97,131 @@
  * @see <a href="https://github.com/apache/accumulo-access";>Accumulo Access 
Documentation</a>
  * @since 1.0.0
  */
-public interface AccessExpression extends Serializable {
+public abstract class AccessExpression implements Serializable {
+  /*
+   * This is package private so that it can not be extended by classes outside 
of this package and
+   * create a mutable implementation. In this package all implementations that 
extends are
+   * immutable.
+   */
+  AccessExpression() {}
 
   /**
    * @return the expression that was used to create this object.
    */
-  String getExpression();
+  public abstract String getExpression();
 
-  /**
-   * @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();
+  @Override
+  public boolean equals(Object o) {
+    if (o instanceof AccessExpression) {
+      return ((AccessExpression) o).getExpression().equals(getExpression());
+    }
 
-  /**
-   * This is equivalent to calling {@code AccessExpression.of(expression, 
false);}
-   */
-  static AccessExpression of(String expression) throws 
InvalidAccessExpressionException {
-    return new AccessExpressionImpl(expression, false);
+    return false;
   }
 
-  /**
-   * <p>
-   * Validates an access expression and creates an immutable AccessExpression 
object.
-   *
-   * <p>
-   * When the {@code normalize} parameter is true, then will deduplicate, 
sort, flatten, and remove
-   * unneeded parentheses or quotes in the expressions. Normalization is done 
in addition to
-   * validation. The following list gives examples of what each normalization 
step does.
-   *
-   * <ul>
-   * <li>As an example of flattening, the expression {@code A&(B&C)} flattens 
to {@code A&B&C}.</li>
-   * <li>As an example of sorting, the expression {@code (Z&Y)|(C&B)} sorts to
-   * {@code (B&C)|(Y&Z)}</li>
-   * <li>As an example of deduplication, the expression {@code X&Y&X} 
normalizes to {@code X&Y}</li>
-   * <li>As an example of unneeded quotes, the expression {@code "ABC"&"XYZ"} 
normalizes to
-   * {@code ABC&XYZ}</li>
-   * <li>As an example of unneeded parentheses, the expression {@code 
(((ABC)|(XYZ)))} normalizes to
-   * {@code ABC|XYZ}</li>
-   * </ul>
-   *
-   * @param expression an access expression
-   * @param normalize If true then the expression will be normalized, if false 
the expression will
-   *        only be validated. Normalization is expensive so only use when 
needed. If repeatedly
-   *        normalizing expressions, consider using a cache that maps 
un-normalized expressions to
-   *        normalized ones. Since the normalization process is deterministic, 
the computation can
-   *        be cached.
-   * @throws InvalidAccessExpressionException when the expression is not valid.
-   */
-  static AccessExpression of(String expression, boolean normalize)
-      throws InvalidAccessExpressionException {
-    return new AccessExpressionImpl(expression, normalize);
+  @Override
+  public int hashCode() {
+    return getExpression().hashCode();
+  }
+
+  @Override
+  public String toString() {
+    return getExpression();
   }
 
   /**
-   * <p>
    * This is equivalent to calling {@code AccessExpression.of(expression, 
false);}
    */
-  static AccessExpression of(byte[] expression) throws 
InvalidAccessExpressionException {
-    return new AccessExpressionImpl(expression, false);
+  public static AccessExpression of(String expression) throws 
InvalidAccessExpressionException {
+    return new AccessExpressionImpl(expression);
   }
 
   /**
    * <p>
-   * Validates an access expression and creates an immutable AccessExpression 
object.
-   *
-   * <p>
-   * If only validation is needed, then call {@link #validate(byte[])} because 
it will avoid copying
-   * the expression like this method does. This method must copy the byte 
array into a String in
-   * order to create an immutable AccessExpression.
-   *
-   * @see #of(String, boolean) for information about normlization.
-   * @param expression an access expression that is expected to be encoded 
using UTF-8
-   * @param normalize If true then the expression will be normalized, if false 
the expression will
-   *        only be validated. Normalization is expensive so only use when 
needed.
-   * @throws InvalidAccessExpressionException when the expression is not valid.
+   * This is equivalent to calling {@code AccessExpression.of(expression, 
false);}
    */
-  static AccessExpression of(byte[] expression, boolean normalize)
-      throws InvalidAccessExpressionException {
-    return new AccessExpressionImpl(expression, normalize);
+  public static AccessExpression of(byte[] expression) throws 
InvalidAccessExpressionException {
+    return new AccessExpressionImpl(expression);
   }
 
   /**
    * @return an empty AccessExpression that is immutable.
    */
-  static AccessExpression of() {
+  public static AccessExpression of() {
     return AccessExpressionImpl.EMPTY;
   }
 
+  public static ParsedAccessExpression parse(byte[] expression) {
+    if (expression.length == 0) {
+      return ParsedAccessExpressionImpl.EMPTY;
+    }
+
+    return 
ParsedAccessExpressionImpl.parseExpression(Arrays.copyOf(expression, 
expression.length));
+  }
+
+  public static ParsedAccessExpression parse(String expression) {
+    if (expression.isEmpty()) {
+      return ParsedAccessExpressionImpl.EMPTY;
+    }
+    return 
ParsedAccessExpressionImpl.parseExpression(expression.getBytes(UTF_8));

Review Comment:
   It is doing that to avoid copying the byte array twice.  I added a comment 
in the code about that.



-- 
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]

Reply via email to