jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1344296 - in /jackrabbit/oak/trunk: oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/ oak-mk/src/main/java/org/apache/jackrabbit/mk/core/ oak-mk/src/main/java/org/apache/jackrabbit/mk/model/
Date Wed, 30 May 2012 15:06:17 GMT
Author: stefan
Date: Wed May 30 15:06:16 2012
New Revision: 1344296

URL: http://svn.apache.org/viewvc?rev=1344296&view=rev
Log:
OAK-77: Consolidate Utilities

remove redundant split(path) method

Modified:
    jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/Repository.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java

Modified: jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java?rev=1344296&r1=1344295&r2=1344296&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/PathUtils.java
Wed May 30 15:06:16 2012
@@ -22,7 +22,7 @@ import java.util.Iterator;
 import java.util.NoSuchElementException;
 
 /**
- * Utility methods to parse a JCR path.
+ * Utility methods to parse a path.
  * <p/>
  * Each method validates the input, except if the system property
  * {packageName}.SKIP_VALIDATION is set, in which case only minimal validation
@@ -163,43 +163,8 @@ public class PathUtils {
     }
 
     /**
-     * Split a path into elements. The root path ("/") and the empty path ("")
-     * is zero elements.
-     *
-     * @param path the path
-     * @return the path elements
-     */
-    @Nonnull
-    public static String[] split(String path) {
-        assert isValid(path);
-
-        if (path.isEmpty()) {
-            return EMPTY_ARRAY;
-        } else if (isAbsolutePath(path)) {
-            if (path.length() == 1) {
-                return EMPTY_ARRAY;
-            }
-            path = path.substring(1);
-        }
-        ArrayList<String> list = new ArrayList<String>();
-        while (true) {
-            int index = path.indexOf('/');
-            if (index < 0) {
-                list.add(path);
-                break;
-            }
-            String s = path.substring(0, index);
-            list.add(s);
-            path = path.substring(index + 1);
-        }
-        String[] array = new String[list.size()];
-        list.toArray(array);
-        return array;
-    }
-
-    /**
-     * Split a path into elements. The root path ("/") and the empty path ("")
-     * is zero elements.
+     * Returns an {@code Iterable} for the path elements. The root path ("/") and the
+     * empty path ("") have zero elements.
      *
      * @param path the path
      * @return an Iterable for the path elements

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/Repository.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/Repository.java?rev=1344296&r1=1344295&r2=1344296&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/Repository.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/core/Repository.java
Wed May 30 15:06:16 2012
@@ -167,7 +167,7 @@ public class Repository {
         }
 
         NodeState node = rs.getNodeState(rs.getRootNode(revId));
-        for (String name : PathUtils.split(path)) {
+        for (String name : PathUtils.elements(path)) {
             node = node.getChildNode(name);
             if (node == null) {
                 break;
@@ -184,7 +184,7 @@ public class Repository {
         }
 
         NodeState node = rs.getNodeState(rs.getRootNode(revId));
-        for (String name : PathUtils.split(path)) {
+        for (String name : PathUtils.elements(path)) {
             node = node.getChildNode(name);
             if (node == null) {
                 return false;

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java?rev=1344296&r1=1344295&r2=1344296&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/CommitBuilder.java
Wed May 30 15:06:16 2012
@@ -252,14 +252,15 @@ public class CommitBuilder {
                 staged.put("/", parent);
             }
             node = parent;
-            String names[] = PathUtils.split(nodePath);
-            for (int i = names.length - 1; i >= 0; i--) {
-                String path = PathUtils.getAncestorPath(nodePath, i);
+
+            int nth = PathUtils.getDepth(nodePath) - 1;
+            for (String name : PathUtils.elements(nodePath)) {
+                String path = PathUtils.getAncestorPath(nodePath, nth--);
                 node = staged.get(path);
                 if (node == null) {
                     // not yet staged, resolve id using staged parent
                     // to allow for staged move operations
-                    ChildNode cne = parent.getChildNodeEntry(names[names.length - i - 1]);
+                    ChildNode cne = parent.getChildNodeEntry(name);
                     if (cne == null) {
                         throw new NotFoundException(nodePath);
                     }



Mime
View raw message