arne-bdt commented on code in PR #1918:
URL: https://github.com/apache/jena/pull/1918#discussion_r1241271797


##########
jena-core/src/main/java/org/apache/jena/mem2/iterator/NestedIterator.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.jena.mem2.iterator;
+
+import org.apache.jena.util.iterator.ExtendedIterator;
+import org.apache.jena.util.iterator.NiceIterator;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+/**
+ * Iterator that iterates over the elements of an iterator of iterators.
+ * The inner iterators are created by a mapper function.
+ *
+ * @param <E> the type of the elements
+ * @param <I> the type of the inner iterators
+ */
+public class NestedIterator<E, I> extends NiceIterator<E> {
+
+    final Iterator<I> parentIterator;
+    final Function<I, ExtendedIterator<E>> mapper;
+    ExtendedIterator<E> currentIterator;
+
+    private boolean hasNext = false;
+
+    public NestedIterator(Iterator<I> parentIterator, Function<I, 
ExtendedIterator<E>> mapper) {
+        this.parentIterator = parentIterator;
+        this.mapper = mapper;
+        this.currentIterator = parentIterator.hasNext()
+                ? mapper.apply(parentIterator.next())
+                : NiceIterator.emptyIterator();
+    }
+
+    @Override
+    @SuppressWarnings("squid:S1121")
+    public boolean hasNext() {
+        if (this.currentIterator.hasNext()) {
+            return hasNext = true;
+        }
+        while (this.parentIterator.hasNext()) {
+            this.currentIterator = 
this.mapper.apply(this.parentIterator.next());
+            if (this.currentIterator.hasNext()) {
+                return hasNext = true;
+            }
+        }
+        return hasNext = false;

Review Comment:
   I adopted your suggestion (not here but in my IDE)



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to