tkalkirill commented on a change in pull request #589:
URL: https://github.com/apache/ignite-3/pull/589#discussion_r793496628



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/util/CollectionUtils.java
##########
@@ -197,13 +202,100 @@ public T next() {
         };
     }
 
+    /**
+     * Create a lazy concatenation of iterators.
+     *
+     * <p>NOTE: {@link Iterator#remove} - not supported.
+     *
+     * @param iterators Iterators.
+     * @param <T> Type of the elements.
+     * @return Concatenation of iterators.
+     */
+    @SafeVarargs
+    public static <T> Iterator<T> concat(@Nullable Iterator<? extends T>... 
iterators) {

Review comment:
       I wrote above about the impossibility of using streams now.

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/util/CollectionUtils.java
##########
@@ -197,13 +202,100 @@ public T next() {
         };
     }
 
+    /**
+     * Create a lazy concatenation of iterators.
+     *
+     * <p>NOTE: {@link Iterator#remove} - not supported.
+     *
+     * @param iterators Iterators.
+     * @param <T> Type of the elements.
+     * @return Concatenation of iterators.
+     */
+    @SafeVarargs
+    public static <T> Iterator<T> concat(@Nullable Iterator<? extends T>... 
iterators) {
+        if (iterators == null || iterators.length == 0) {
+            return emptyIterator();
+        }
+
+        return new Iterator<>() {
+            /** Current index at {@code iterators}. */
+            int idx = 0;
+
+            /** Current iterator. */
+            Iterator<? extends T> curr = emptyIterator();
+
+            /** {@inheritDoc} */
+            @Override
+            public boolean hasNext() {
+                while (!curr.hasNext() && idx < iterators.length) {
+                    curr = iterators[idx++];
+                }
+
+                return curr.hasNext();
+            }
+
+            /** {@inheritDoc} */
+            @Override
+            public T next() {
+                if (!hasNext()) {
+                    throw new NoSuchElementException();
+                } else {
+                    return curr.next();
+                }
+            }
+        };
+    }
+
+    /**
+     * Create a lazy concatenation of iterators.
+     *
+     * <p>NOTE: {@link Iterator#remove} - not supported.
+     *
+     * @param iterators Iterators.
+     * @param <T> Type of the elements.
+     * @return Concatenation of iterators.
+     */
+    public static <T> Iterator<T> concat(@Nullable Collection<Iterator<? 
extends T>> iterators) {

Review comment:
       I wrote above about the impossibility of using streams now.




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