You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/02/22 13:58:35 UTC
svn commit: r630188 - in /incubator/sling/trunk/jcr/resource/src:
main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java
test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java
Author: fmeschbe
Date: Fri Feb 22 04:58:35 2008
New Revision: 630188
URL: http://svn.apache.org/viewvc?rev=630188&view=rev
Log:
SLING-269 Fix test cases and iterator for null and empty paths
Modified:
incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java
incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java
Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java?rev=630188&r1=630187&r2=630188&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java (original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIterator.java Fri Feb 22 04:58:35 2008
@@ -40,29 +40,37 @@
/**
* Creates a new instance iterating over the given path
- *
+ *
* @param path The path to iterate over. If this is empty or
* <code>null</code> this iterator will not return anything.
*/
public ResourcePathIterator(String path) {
- // find last non-slash character
- int i = (path != null) ? path.length() - 1 : -1;
- while (i >= 0 && path.charAt(i) == '/') {
- i--;
- }
-
- if (i < 0) {
- // only slashes, assume root node
- nextPath = "/";
-
- } else if (i < path.length() - 1) {
- // cut off slash
- nextPath = path.substring(0, i + 1);
+ if (path == null || path.length() == 0) {
+
+ // null or empty path, there is nothing to return
+ nextPath = null;
} else {
- // no trailing slash
- nextPath = path;
+
+ // find last non-slash character
+ int i = (path != null) ? path.length() - 1 : -1;
+ while (i >= 0 && path.charAt(i) == '/') {
+ i--;
+ }
+
+ if (i < 0) {
+ // only slashes, assume root node
+ nextPath = "/";
+
+ } else if (i < path.length() - 1) {
+ // cut off slash
+ nextPath = path.substring(0, i + 1);
+
+ } else {
+ // no trailing slash
+ nextPath = path;
+ }
}
}
Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java?rev=630188&r1=630187&r2=630188&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java (original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/ResourcePathIteratorTest.java Fri Feb 22 04:58:35 2008
@@ -37,6 +37,7 @@
public void testRoot() {
ResourcePathIterator rpi = new ResourcePathIterator("/");
+ assertNext("/", rpi);
assertFinished(rpi);
}