jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1173065 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/util/PathUtils.java test/java/org/apache/jackrabbit/mk/util/PathTest.java
Date Tue, 20 Sep 2011 10:23:07 GMT
Author: thomasm
Date: Tue Sep 20 10:23:06 2011
New Revision: 1173065

URL: http://svn.apache.org/viewvc?rev=1173065&view=rev
Log:
New PathUtils method 'isParent'

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/PathTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java?rev=1173065&r1=1173064&r2=1173065&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
Tue Sep 20 10:23:06 2011
@@ -115,8 +115,8 @@ public class PathUtils {
     }
 
     /**
-     * Calculate the number of elements in the path.
-     * The root path has zero elements.
+     * Calculate the number of elements in the path. The root path has zero
+     * elements.
      *
      * @param path the path
      * @return the number of elements
@@ -177,7 +177,7 @@ public class PathUtils {
     /**
      * Concatenate path elements.
      *
-     * @param parentPath    the parent path
+     * @param parentPath the parent path
      * @param relativePaths the relative path elements to add
      * @return the concatenated path
      */
@@ -208,7 +208,7 @@ public class PathUtils {
     /**
      * Concatenate path elements.
      *
-     * @param parentPath   the parent path
+     * @param parentPath the parent path
      * @param relativePath the relative path to add
      * @return the concatenated path
      */
@@ -232,12 +232,25 @@ public class PathUtils {
     }
 
     /**
+     * Check if a path is the (direct or indirect) parent of another path.
+     *
+     * @param parent the parent path
+     * @param path the possible child path
+     * @return true if the path is a child of the parent
+     */
+    public static boolean isParent(String parent, String path) {
+        assertValid(parent);
+        assertValid(path);
+        return path.startsWith(parent) && path.length() > parent.length();
+    }
+
+    /**
      * Relativize a path wrt. a parent path such that
      * <code>relativize(parentPath, concat(parentPath, path)) == paths</code>
      * holds.
      *
      * @param parentPath parent pth
-     * @param path       path to relativize
+     * @param path path to relativize
      * @return relativized path
      */
     public static String relativize(String parentPath, String path) {
@@ -261,10 +274,10 @@ public class PathUtils {
     /**
      * Get the index of the next slash.
      *
-     * @param path  the path
+     * @param path the path
      * @param index the starting index
-     * @return the index of the next slash (possibly the starting index), or
-     *         -1 if not found
+     * @return the index of the next slash (possibly the starting index), or -1
+     *         if not found
      */
     public static int getNextSlash(String path, int index) {
         assertValid(path);

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/PathTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/PathTest.java?rev=1173065&r1=1173064&r2=1173065&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/PathTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/PathTest.java
Tue Sep 20 10:23:06 2011
@@ -106,6 +106,13 @@ public class PathTest extends TestCase {
         assertEquals(true, PathUtils.isAbsolute("/" + parent + "/" + child));
         assertEquals(false, PathUtils.isAbsolute(parent + "/" + child));
 
+        // isParent
+        assertTrue(PathUtils.isParent("/", "/" + parent));
+        assertTrue(PathUtils.isParent(parent, parent + "/" + child));
+        assertFalse(PathUtils.isParent("/", parent + "/" + child));
+        assertTrue(PathUtils.isParent("/" + parent, "/" + parent + "/" + child));
+        assertFalse(PathUtils.isParent(parent, child));
+
         // relativize
         assertEquals("", PathUtils.relativize("/", "/"));
         assertEquals("", PathUtils.relativize("/" + parent, "/" + parent));



Mime
View raw message