joerghoh commented on code in PR #132:
URL: 
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/132#discussion_r1922319108


##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java:
##########
@@ -1686,12 +1688,19 @@ private void logDisableAliasOptimization(final 
Exception e) {
                 log.error("A problem occured during initialization of optimize 
alias resolution. Optimize alias resolution is disabled. Check the logs for the 
reported problem.", e);
             }
         }
-
     }
 
-    private final class MapEntryIterator implements Iterator<MapEntry> {
+    // return vanity path entry iterator from cache when complete and ready, 
otherwise from
+    // regular lockup
+    public @Nullable List<MapEntry> getCurrentMapEntryForVanityPath(final 
String key) {

Review Comment:
   ```suggestion
       public @Nullable List<MapEntry> getCurrentMapEntryForVanityPath(@NotNull 
final String key) {
   ```



##########
src/test/java/org/apache/sling/resourceresolver/impl/mapping/MapEntryIteratorTest.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.resourceresolver.impl.mapping;
+
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
+
+public class MapEntryIteratorTest {
+
+    private final MapEntries.MapEntryIterator empty =
+            new MapEntries.MapEntryIterator(null, List.of(), key -> 
Collections.emptyList(), true);
+
+    private final MapEntry xyz =
+            new MapEntry("/xyz", -1, false, -1, "/foo", "/bar");
+
+    private final MapEntry global =
+            new MapEntry("/foo/global/long", -1, false, -1, "bla");
+
+    private final Map<String, List<MapEntry>> xyzMap =
+            Map.of("/xyz", List.of(xyz));
+
+    @Test
+    public void testExhausted() {
+        assertFalse(empty.hasNext());
+        assertThrows(NoSuchElementException.class,
+                empty::next);
+    }
+
+    @Test
+    public void testRemove() {
+        assertFalse(empty.hasNext());
+        assertThrows(UnsupportedOperationException.class,

Review Comment:
   just for curiosity: Why do you ``assertThrows`` instead of annotating the 
``@Test`` annotation with the expected Exception class?



##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java:
##########
@@ -1704,12 +1713,15 @@ private final class MapEntryIterator implements 
Iterator<MapEntry> {
         private MapEntry nextSpecial;
 
         private boolean vanityPathPrecedence;
+        private final Function<String, List<MapEntry>> 
getCurrentMapEntryForVanityPath;
 
-        public MapEntryIterator(final String startKey, final Map<String, 
List<MapEntry>> resolveMapsMap, final boolean vanityPathPrecedence) {
+        public MapEntryIterator(final String startKey, @NotNull final 
List<MapEntry> globalList,
+                                final Function<String, List<MapEntry>> 
getCurrentMapEntryForVanityPath,

Review Comment:
   Right now I don't see the need for the parameter 
``getCurrentMapEntryForVanityPath``, as this method is only used in this class. 
   Will this change in the future?



##########
src/main/java/org/apache/sling/resourceresolver/impl/mapping/MapEntries.java:
##########
@@ -1704,12 +1713,15 @@ private final class MapEntryIterator implements 
Iterator<MapEntry> {
         private MapEntry nextSpecial;
 
         private boolean vanityPathPrecedence;
+        private final Function<String, List<MapEntry>> 
getCurrentMapEntryForVanityPath;
 
-        public MapEntryIterator(final String startKey, final Map<String, 
List<MapEntry>> resolveMapsMap, final boolean vanityPathPrecedence) {
+        public MapEntryIterator(final String startKey, @NotNull final 
List<MapEntry> globalList,

Review Comment:
   Can you add the ``NotNull`` resp. ``@Nullable`` annotation for all values?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to