accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject [1/3] git commit: ACCUMULO-1730 set offsets for AND and OR parse nodes
Date Mon, 23 Sep 2013 15:57:45 GMT
Updated Branches:
  refs/heads/master 864f5a0ed -> 8103017cf


ACCUMULO-1730 set offsets for AND and OR parse nodes


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/c091b545
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/c091b545
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/c091b545

Branch: refs/heads/master
Commit: c091b545a7f79efb3dc9b8b279cfb4465b476ecc
Parents: 70fe481
Author: Eric Newton <eric.newton@gmail.com>
Authored: Mon Sep 23 11:56:10 2013 -0400
Committer: Eric Newton <eric.newton@gmail.com>
Committed: Mon Sep 23 11:56:10 2013 -0400

----------------------------------------------------------------------
 .../core/security/ColumnVisibility.java         | 13 ++++++-----
 .../core/security/ColumnVisibilityTest.java     | 23 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/c091b545/src/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
----------------------------------------------------------------------
diff --git a/src/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
b/src/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
index a7ac8e0..88be51f 100644
--- a/src/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
+++ b/src/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
@@ -52,12 +52,14 @@ public class ColumnVisibility {
   public static class Node {
     public final static List<Node> EMPTY = Collections.emptyList();
     NodeType type;
-    int start = 0;
-    int end = 0;
+    final int start;
+    final int end;
     List<Node> children = EMPTY;
     
-    public Node(NodeType type) {
+    public Node(NodeType type, int start) {
       this.type = type;
+      this.start = start;
+      this.end = start + 1;
     }
     
     public Node(int start, int end) {
@@ -189,7 +191,7 @@ public class ColumnVisibility {
               if (!result.type.equals(NodeType.AND))
                 throw new BadArgumentException("cannot mix & and |", new String(expression),
index - 1);
             } else {
-              result = new Node(NodeType.AND);
+              result = new Node(NodeType.AND, index - 1);
             }
             result.add(expr);
             expr = null;
@@ -202,7 +204,7 @@ public class ColumnVisibility {
               if (!result.type.equals(NodeType.OR))
                 throw new BadArgumentException("cannot mix | and &", new String(expression),
index - 1);
             } else {
-              result = new Node(NodeType.OR);
+              result = new Node(NodeType.OR, index - 1);
             }
             result.add(expr);
             expr = null;
@@ -229,7 +231,6 @@ public class ColumnVisibility {
                 result.add(c);
             else
               result.add(child);
-            result.end = index - 1;
             return result;
           }
           default: {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/c091b545/src/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java
----------------------------------------------------------------------
diff --git a/src/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java
b/src/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java
index df1863a..930e332 100644
--- a/src/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java
+++ b/src/core/src/test/java/org/apache/accumulo/core/security/ColumnVisibilityTest.java
@@ -18,7 +18,10 @@ package org.apache.accumulo.core.security;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
+import org.apache.accumulo.core.security.ColumnVisibility.Node;
+import org.apache.accumulo.core.security.ColumnVisibility.NodeType;
 import org.junit.Test;
 
 public class ColumnVisibilityTest {
@@ -108,4 +111,24 @@ public class ColumnVisibilityTest {
     shouldThrow("(A&B)|(C&D)&(E)");
     shouldThrow("a|b&c", "A&B&C|D", "(A&B)|(C&D)&(E)");
   }
+  
+  @Test
+  public void testParseTree() {
+    String s = "(W)|(U&V)";
+    ColumnVisibility v = new ColumnVisibility(s);
+    Node node = v.getParseTree();
+    assertNode(node, NodeType.OR, 3, 4);
+    assertNode(node.getChildren().get(0), NodeType.TERM, 1, 2);
+    assertNode(node.getChildren().get(1), NodeType.AND, 6, 7);
+    assertNode(node.getChildren().get(1).children.get(0), NodeType.TERM, 5, 6);
+    assertNode(node.getChildren().get(1).children.get(1), NodeType.TERM, 7, 8);
+  }
+
+  private void assertNode(Node node, NodeType nodeType, int start, int end) {
+    assertEquals(node.type, nodeType);
+    assertEquals(start, node.start);
+    assertEquals(end, node.end);
+    
+  }
+  
 }


Mime
View raw message