This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit fa1d8f047d8ed01511084074751d06bb1a71c180
Author: Robert Munteanu <[email protected]>
AuthorDate: Fri Aug 7 13:42:44 2020 +0200

    SLING-9620 - ResourceMapperImpl.getAllMappings does not respect 
multi-valued sling:alias
    
    Rename PathBuilder to PathGenerator, to better reflect its purpose. Also 
add some Javadoc to that class.
---
 .../{PathBuilder.java => PathGenerator.java}       | 26 ++++++++++------
 .../impl/mapping/ResourceMapperImpl.java           |  4 +--
 ...PathBuilderTest.java => PathGeneratorTest.java} | 36 +++++++++++-----------
 3 files changed, 36 insertions(+), 30 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/PathBuilder.java 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/PathGenerator.java
similarity index 77%
rename from 
src/main/java/org/apache/sling/resourceresolver/impl/mapping/PathBuilder.java
rename to 
src/main/java/org/apache/sling/resourceresolver/impl/mapping/PathGenerator.java
index 207e557..53b298c 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/PathBuilder.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/PathGenerator.java
@@ -27,10 +27,16 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 /**
- * Utility to construct paths from segments, starting with the leaf-most ones
+ * Utility to generate all possible paths from segments (names)
+ * 
+ * <p>This class expects to be supplied segments starting with the top-most 
ones (leaves)
+ * up until, but excluding, the root.</p>
+ * 
+ * <p>It generates all possible path combinations using a cartesian product 
that accummulates
+ * using a {@link StringBuilder} instead of a set, to prevent intermediate 
object creation.</p>
  *
  */
-public class PathBuilder {
+public class PathGenerator {
     
     private static List<String> cartesianJoin(List<List<String>> segments, 
String toAppend) {
         
@@ -69,7 +75,7 @@ public class PathBuilder {
     /**
      * Inserts a new segment as the parent of the existing ones
      * 
-     * @param alias the alias, ignored if null or empty
+     * @param alias the list of aliases
      * @param name the name
      */
     public void insertSegment(@NotNull List<String> alias, @NotNull String 
name) {
@@ -83,20 +89,20 @@ public class PathBuilder {
     }
     
     /**
-     * Sets a new value to append, typically the resolution info
+     * Sets the resolution info, to be appended at the end
      * 
-     * @param toAppend the parameters to append, ignored if null or empty
+     * @param resolutionInfo the resolution info to append, ignored if null or 
empty
      */
-    public void setResolutionPathInfo(@Nullable String toAppend) {
-        this.toAppend = toAppend;
+    public void setResolutionPathInfo(@Nullable String resolutionInfo) {
+        this.toAppend = resolutionInfo;
     }
     
     /**
-     * Constructs a new path from the provided information
+     * Generates all possible paths
      * 
-     * @return a path in string form
+     * @return a list of paths containing at least one entry
      */
-    public List<String> toPaths() {
+    public List<String> generatePaths() {
         return cartesianJoin(segments, toAppend);
     }
 }
diff --git 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
index acc4707..89f2859 100644
--- 
a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
+++ 
b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/ResourceMapperImpl.java
@@ -185,7 +185,7 @@ public class ResourceMapperImpl implements ResourceMapper {
         // find aliases for segments. we can't walk the parent chain
         // since the request session might not have permissions to
         // read all parents SLING-2093
-        PathBuilder pathBuilder = new PathBuilder();
+        PathGenerator pathBuilder = new PathGenerator();
 
         // make sure to append resolutionPathInfo, if present
         pathBuilder.setResolutionPathInfo(resolutionPathInfo);
@@ -209,7 +209,7 @@ public class ResourceMapperImpl implements ResourceMapper {
         }
         
         // and then we have the mapped path to work on
-        List<String> mappedPaths = pathBuilder.toPaths();
+        List<String> mappedPaths = pathBuilder.generatePaths();
 
         logger.debug("map: Alias mapping resolves to paths {}", mappedPaths);
         
diff --git 
a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/PathBuilderTest.java
 
b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/PathGeneratorTest.java
similarity index 77%
rename from 
src/test/java/org/apache/sling/resourceresolver/impl/mapping/PathBuilderTest.java
rename to 
src/test/java/org/apache/sling/resourceresolver/impl/mapping/PathGeneratorTest.java
index 79b454b..fc498f1 100644
--- 
a/src/test/java/org/apache/sling/resourceresolver/impl/mapping/PathBuilderTest.java
+++ 
b/src/test/java/org/apache/sling/resourceresolver/impl/mapping/PathGeneratorTest.java
@@ -28,78 +28,78 @@ import java.util.List;
 import org.hamcrest.Matchers;
 import org.junit.Test;
 
-public class PathBuilderTest {
+public class PathGeneratorTest {
 
     @Test
-    public void buildRootPath() {
+    public void rootPath() {
         
-        List<String> paths = new PathBuilder().toPaths();
+        List<String> paths = new PathGenerator().generatePaths();
         
         assertThat(paths, Matchers.hasSize(1));
         assertThat(paths, Matchers.hasItem("/"));
     }
 
     @Test
-    public void buildSubPathWithMissingAliases() {
+    public void subPathWithMissingAliases() {
         
-        PathBuilder builder = new PathBuilder();
+        PathGenerator builder = new PathGenerator();
         builder.insertSegment(singletonList(null), "bar");
         builder.insertSegment(singletonList(""), "foo");
-        List<String> paths = builder.toPaths();
+        List<String> paths = builder.generatePaths();
         
         assertThat(paths, Matchers.hasSize(1));
         assertThat(paths, Matchers.hasItem("/foo/bar"));
     }
 
     @Test
-    public void buildSubPathWithMixedAliases() {
+    public void subPathWithMixedAliases() {
         
-        PathBuilder builder = new PathBuilder();
+        PathGenerator builder = new PathGenerator();
         builder.insertSegment(emptyList(), "bar");
         builder.insertSegment(singletonList("super"), "foo");
-        List<String> paths = builder.toPaths();
+        List<String> paths = builder.generatePaths();
         
         assertThat(paths, Matchers.hasSize(1));
         assertThat(paths, Matchers.hasItem("/super/bar"));
     }
     
     @Test
-    public void buildSubPathWithResolutionInfo() {
+    public void subPathWithResolutionInfo() {
         
-        PathBuilder builder = new PathBuilder();
+        PathGenerator builder = new PathGenerator();
         builder.insertSegment(emptyList(), "bar");
         builder.insertSegment(emptyList(), "foo");
         builder.setResolutionPathInfo("/baz");
         
-        List<String> paths = builder.toPaths();
+        List<String> paths = builder.generatePaths();
         
         assertThat(paths, Matchers.hasSize(1));
         assertThat(paths, Matchers.hasItem("/foo/bar/baz"));        
     }
     
     @Test
-    public void buildSubPathWithMultipleAliases() {
+    public void subPathWithMultipleAliases() {
         
-        PathBuilder builder = new PathBuilder();
+        PathGenerator builder = new PathGenerator();
         builder.insertSegment(emptyList(), "bar");
         builder.insertSegment(asList("alias1", "alias2"), "foo");
         
-        List<String> paths = builder.toPaths();
+        List<String> paths = builder.generatePaths();
         
         assertThat(paths, Matchers.hasSize(2));
         assertThat(paths, Matchers.hasItems("/alias1/bar", "/alias2/bar"));
     }
 
     @Test
-    public void buildSubPathWithComplexAliasesSetup() {
+    public void subPathWithComplexAliasesSetup() {
         
-        PathBuilder builder = new PathBuilder();
+        PathGenerator builder = new PathGenerator();
         builder.insertSegment(asList("4a", "4b", "4c"), "4");
         builder.insertSegment(emptyList(), "3");
         builder.insertSegment(asList("2a", "2b"), "2");
         builder.insertSegment(asList("1a", "1b"), "1");
         
-        List<String> paths = builder.toPaths();
+        List<String> paths = builder.generatePaths();
         
         assertThat(paths, Matchers.hasSize(12));
         assertThat(paths, Matchers.hasItems(

Reply via email to