ibessonov commented on code in PR #2580:
URL: https://github.com/apache/ignite-3/pull/2580#discussion_r1324186283


##########
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/util/ConfigurationUtil.java:
##########
@@ -886,6 +889,124 @@ public static void touch(DynamicConfiguration<?, ?> cfg) {
         }
     }
 
+    /**
+     * Maps iterable via provided mapper function. Filter all {@code null} 
mapped values.
+     *
+     * @param iterable Basic iterable.
+     * @param mapper Conversion function.
+     * @param <T1> Base type of the iterable.
+     * @param <T2> Type for view.
+     * @return Mapped iterable.
+     */
+    public static <T1, T2> Iterable<T2> mapIterable(
+            @Nullable Iterable<? extends T1> iterable,
+            @Nullable Function<? super T1, ? extends T2> mapper
+    ) {
+        if (iterable == null) {
+            return Collections.emptyList();
+        }
+
+        if (mapper == null) {
+            return (Iterable<T2>) iterable;
+        }
+
+        return () -> {
+            Iterator<? extends T1> innerIterator = iterable.iterator();
+            return new Iterator<>() {
+                @Nullable
+                private T2 next;
+
+                @Override
+                public boolean hasNext() {
+                    while (innerIterator.hasNext()) {
+                        next = mapper.apply(innerIterator.next());
+                        if (next != null) {
+                            return true;
+                        }
+                    }
+                    return false;
+                }
+
+                @Override
+                public T2 next() {
+                    if (next == null) {

Review Comment:
   You're breaking the iterator invariant here. If there's an element, `next()` 
must return it, even if you don't call `hasNext()`. Please replace the 
condition with `if (!hasNext()) {`



##########
modules/configuration/src/main/java/org/apache/ignite/internal/configuration/util/ConfigurationUtil.java:
##########
@@ -886,6 +889,124 @@ public static void touch(DynamicConfiguration<?, ?> cfg) {
         }
     }
 
+    /**
+     * Maps iterable via provided mapper function. Filter all {@code null} 
mapped values.
+     *
+     * @param iterable Basic iterable.
+     * @param mapper Conversion function.
+     * @param <T1> Base type of the iterable.
+     * @param <T2> Type for view.
+     * @return Mapped iterable.
+     */
+    public static <T1, T2> Iterable<T2> mapIterable(
+            @Nullable Iterable<? extends T1> iterable,
+            @Nullable Function<? super T1, ? extends T2> mapper
+    ) {
+        if (iterable == null) {
+            return Collections.emptyList();
+        }
+
+        if (mapper == null) {
+            return (Iterable<T2>) iterable;
+        }
+
+        return () -> {
+            Iterator<? extends T1> innerIterator = iterable.iterator();
+            return new Iterator<>() {
+                @Nullable
+                private T2 next;
+
+                @Override
+                public boolean hasNext() {

Review Comment:
   What if you call `hasNext()` several times? It should work, but it won't. 
Please implement the iterator properly



##########
modules/page-memory/src/test/java/org/apache/ignite/internal/pagememory/persistence/store/FilePageStoreManagerTest.java:
##########
@@ -159,6 +157,14 @@ void testInitialize() throws Exception {
         }
     }
 
+    private static void ensure(GroupPartitionPageStore<FilePageStore> 
filePageStore) {
+        try {
+            filePageStore.pageStore().ensure();
+        } catch (IgniteInternalCheckedException e) {
+            throw new RuntimeException(e);

Review Comment:
   Hm? Maybe we shouldn't do this, right? There are two options:
   - proper exception class
   - don't use "forEach", use good old loop
   I like the loop much more



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