jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1442882 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/security/privilege/ main/java/org/apache/jackrabbit/oak/util/ test/java/org/apache/jackrabbit/oak/security/user/
Date Wed, 06 Feb 2013 10:03:02 GMT
Author: angela
Date: Wed Feb  6 10:03:01 2013
New Revision: 1442882

URL: http://svn.apache.org/viewvc?rev=1442882&view=rev
Log:
avoid creating NodeUtil for simple read operations

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionReader.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserInitializerTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionReader.java?rev=1442882&r1=1442881&r2=1442882&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionReader.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeDefinitionReader.java
Wed Feb  6 10:03:01 2013
@@ -23,7 +23,7 @@ import javax.annotation.Nonnull;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition;
-import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.apache.jackrabbit.oak.util.TreeUtil;
 
 import static org.apache.jackrabbit.oak.security.privilege.PrivilegeConstants.PRIVILEGES_PATH;
 import static org.apache.jackrabbit.oak.security.privilege.PrivilegeConstants.REP_AGGREGATES;
@@ -65,10 +65,9 @@ class PrivilegeDefinitionReader {
     //-----------------------------------------------------------< internal >---
     @Nonnull
     static PrivilegeDefinition readDefinition(Tree definitionTree) {
-        NodeUtil n = new NodeUtil(definitionTree);
-        String name = n.getName();
-        boolean isAbstract = n.getBoolean(REP_IS_ABSTRACT);
-        String[] declAggrNames = n.getStrings(REP_AGGREGATES);
+        String name = definitionTree.getName();
+        boolean isAbstract = TreeUtil.getBoolean(definitionTree, REP_IS_ABSTRACT);
+        String[] declAggrNames = TreeUtil.getStrings(definitionTree, REP_AGGREGATES);
 
         return new PrivilegeDefinitionImpl(name, isAbstract, declAggrNames);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java?rev=1442882&r1=1442881&r2=1442882&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
Wed Feb  6 10:03:01 2013
@@ -28,13 +28,11 @@ import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 
 import com.google.common.base.Function;
-import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.TreeLocation;
-import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.namepath.NameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -45,7 +43,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
 import static org.apache.jackrabbit.oak.api.Type.DATE;
 import static org.apache.jackrabbit.oak.api.Type.LONG;
 import static org.apache.jackrabbit.oak.api.Type.NAME;
@@ -175,9 +172,7 @@ public class NodeUtil {
     }
 
     public boolean getBoolean(String name) {
-        PropertyState property = tree.getProperty(name);
-        return property != null && !property.isArray()
-                && property.getValue(BOOLEAN);
+        return TreeUtil.getBoolean(tree, name);
     }
 
     public void setBoolean(String name, boolean value) {
@@ -186,12 +181,8 @@ public class NodeUtil {
 
     @CheckForNull
     public String getString(String name, @Nullable String defaultValue) {
-        PropertyState property = tree.getProperty(name);
-        if (property != null && !property.isArray()) {
-            return property.getValue(Type.STRING);
-        } else {
-            return defaultValue;
-        }
+        String str = TreeUtil.getString(tree, name);
+        return (str != null) ? str : defaultValue;
     }
 
     public void setString(String name, String value) {
@@ -200,12 +191,7 @@ public class NodeUtil {
 
     @CheckForNull
     public String[] getStrings(String name) {
-        PropertyState property = tree.getProperty(name);
-        if (property == null) {
-            return null;
-        }
-
-        return Iterables.toArray(property.getValue(STRINGS), String.class);
+        return TreeUtil.getStrings(tree, name);
     }
 
     public void setStrings(String name, String... values) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java?rev=1442882&r1=1442881&r2=1442882&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
Wed Feb  6 10:03:01 2013
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
 
+import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
 import static org.apache.jackrabbit.oak.api.Type.STRINGS;
 
 /**
@@ -59,4 +60,9 @@ public final class TreeUtil {
             return null;
         }
     }
+
+    public static boolean getBoolean(Tree tree, String propertyName) {
+        PropertyState property = tree.getProperty(propertyName);
+        return property != null && !property.isArray() && property.getValue(BOOLEAN);
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserInitializerTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserInitializerTest.java?rev=1442882&r1=1442881&r2=1442882&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserInitializerTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/security/user/UserInitializerTest.java
Wed Feb  6 10:03:01 2013
@@ -26,7 +26,7 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.apache.jackrabbit.oak.spi.security.principal.AdminPrincipal;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.security.user.util.UserUtility;
-import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.apache.jackrabbit.oak.util.TreeUtil;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -109,9 +109,8 @@ public class UserInitializerTest extends
 
     private static void assertIndexDefinition(Tree tree, String propName, boolean isUnique)
{
         assertNotNull(tree);
-        NodeUtil node = new NodeUtil(tree);
 
-        assertEquals(isUnique, node.getBoolean(IndexConstants.UNIQUE_PROPERTY_NAME));
-        assertArrayEquals(new String[] {propName}, node.getNames(IndexConstants.PROPERTY_NAMES));
+        assertEquals(isUnique, TreeUtil.getBoolean(tree, IndexConstants.UNIQUE_PROPERTY_NAME));
+        assertArrayEquals(propName, new String[] {propName}, TreeUtil.getStrings(tree, IndexConstants.PROPERTY_NAMES));
     }
 }
\ No newline at end of file



Mime
View raw message