Author: cziegeler
Date: Tue Oct 18 06:22:00 2016
New Revision: 1765394

URL: http://svn.apache.org/viewvc?rev=1765394&view=rev
Log:
SLING-6056 : achieve 1:1 mapping between observation and resource change 
listener

Modified:
    
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/PathSet.java
    
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathSetTest.java

Modified: 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/PathSet.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/PathSet.java?rev=1765394&r1=1765393&r2=1765394&view=diff
==============================================================================
--- 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/PathSet.java
 (original)
+++ 
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/path/PathSet.java
 Tue Oct 18 06:22:00 2016
@@ -142,7 +142,7 @@ public class PathSet implements Iterable
      * Generate a path set of paths from this set which
      * are in the sub tree of the provided path
      * @param path The base path
-     * @return Path set
+     * @return Path set, might be empty
      */
     public PathSet getSubset(final String path) {
         return getSubset(new Path(path));
@@ -152,7 +152,8 @@ public class PathSet implements Iterable
      * Generate a path set of paths from this set which
      * are in the sub tree of the provided path
      * @param path The base path
-     * @return Path set
+     * @return Path set, might be empty
+     * @since 1.2.0 (Sling API Bundle 2.15.0)
      */
     public PathSet getSubset(final Path path) {
         final Set<Path> result = new HashSet<Path>();
@@ -161,6 +162,22 @@ public class PathSet implements Iterable
                 result.add(p);
             }
         }
+        return new PathSet(result);
+    }
+
+    /**
+     * Generate a path set of paths from this set which
+     * are in at least one of the sub tree of the provided path set.
+     * @param path The base path
+     * @return Path set
+     */
+    public PathSet getSubset(final PathSet set) {
+        final Set<Path> result = new HashSet<Path>();
+        for(final Path p : this.paths) {
+            if ( set.matches(p.getPath()) != null ) {
+                result.add(p);
+            }
+        }
         return new PathSet(result);
     }
 

Modified: 
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathSetTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathSetTest.java?rev=1765394&r1=1765393&r2=1765394&view=diff
==============================================================================
--- 
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathSetTest.java
 (original)
+++ 
sling/trunk/bundles/api/src/test/java/org/apache/sling/api/resource/path/PathSetTest.java
 Tue Oct 18 06:22:00 2016
@@ -27,8 +27,6 @@ import static org.junit.Assert.fail;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.sling.api.resource.path.Path;
-import org.apache.sling.api.resource.path.PathSet;
 import org.junit.Test;
 
 public class PathSetTest {
@@ -124,4 +122,12 @@ public class PathSetTest {
             // expected
         }
     }
+
+    @Test public void testSubsetByPathSet() {
+        final PathSet set = PathSet.fromStrings("/libs/foo/bar", 
"/apps/foo/bar", "/content");
+        final PathSet filter = PathSet.fromStrings("/libs", "/apps");
+
+        final PathSet result = set.getSubset(filter);
+        assertEqualSets(result, "/libs/foo/bar", "/apps/foo/bar");
+    }
 }


Reply via email to