maksaska commented on code in PR #11995:
URL: https://github.com/apache/ignite/pull/11995#discussion_r2055949180


##########
modules/core/src/main/java/org/apache/ignite/internal/util/lang/ClusterNodeFunc.java:
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.ignite.internal.util.lang;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.ignite.cluster.BaselineNode;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.internal.binary.BinaryArray;
+import org.apache.ignite.internal.util.F0;
+import org.apache.ignite.internal.util.lang.gridfunc.ContainsNodeIdsPredicate;
+import 
org.apache.ignite.internal.util.lang.gridfunc.EqualsClusterNodeIdPredicate;
+import org.apache.ignite.internal.util.lang.gridfunc.IsAllPredicate;
+import org.apache.ignite.internal.util.lang.gridfunc.NoOpClosure;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.lang.IgnitePredicate;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Contains factory and utility methods for {@code closures}, {@code 
predicates}, and {@code tuples}.
+ * It also contains functional style collection comprehensions.
+ * <p>
+ * Most of the methods in this class can be divided into two groups:
+ * <ul>
+ * <li><b>Factory</b> higher-order methods for closures, predicates and 
tuples, and</li>
+ * <li><b>Utility</b> higher-order methods for processing collections with 
closures and predicates.</li>
+ * </ul>
+ * Note that contrary to the usual design this class has substantial number of
+ * methods (over 200). This design is chosen to simulate a global namespace
+ * (like a {@code Predef} in Scala) to provide general utility and functional
+ * programming functionality in a shortest syntactical context using {@code F}
+ * typedef.
+ * <p>
+ * Also note, that in all methods with predicates, null predicate has a {@code 
true} meaning. So does
+ * the empty predicate array.
+ */
+@SuppressWarnings("unchecked")
+public class ClusterNodeFunc {
+    /** */
+    private static final GridAbsClosure NOOP = new NoOpClosure();
+
+    /**
+     * Convenient utility method that returns collection of node IDs for a 
given
+     * collection of grid nodes.
+     * <p>
+     * Note that this method doesn't create a new collection but simply 
iterates
+     * over the input one.
+     *
+     * @param nodes Collection of grid nodes.
+     * @return Collection of node IDs for given collection of grid nodes.
+     */
+    public static Collection<UUID> nodeIds(@Nullable Collection<? extends 
ClusterNode> nodes) {
+        if (nodes == null || nodes.isEmpty())
+            return Collections.emptyList();
+
+        return F.viewReadOnly(nodes, ClusterNode::id);
+    }
+
+    /**
+     * Convenient utility method that returns collection of node consistent 
IDs for a given
+     * collection of grid nodes.
+     * <p>
+     * Note that this method doesn't create a new collection but simply 
iterates
+     * over the input one.
+     *
+     * @param nodes Collection of grid nodes.
+     * @return Collection of node consistent IDs for given collection of grid 
nodes.
+     */
+    public static Collection<Object> nodeConsistentIds(@Nullable Collection<? 
extends BaselineNode> nodes) {
+        if (nodes == null || nodes.isEmpty())
+            return Collections.emptyList();
+
+        return F.viewReadOnly(nodes, BaselineNode::consistentId);
+    }
+
+    /**
+     * Creates grid node predicate evaluating on the given node ID.
+     *
+     * @param nodeId Node ID for which returning predicate will evaluate to 
{@code true}.
+     * @return Grid node predicate evaluating on the given node ID.
+     * @see F#idForNodeId(UUID)
+     * @see #nodeIds(Collection)
+     */
+    public static <T extends ClusterNode> IgnitePredicate<T> 
nodeForNodeId(final UUID nodeId) {
+        A.notNull(nodeId, "nodeId");
+
+        return new EqualsClusterNodeIdPredicate<>(nodeId);
+    }
+
+    /**
+     * Creates grid node predicate evaluating on the given node IDs.
+     *
+     * @param nodeIds Collection of node IDs.
+     * @return Grid node predicate evaluating on the given node IDs.
+     * @see F#idForNodeId(UUID)
+     * @see #nodeIds(Collection)
+     */
+    public static <T extends ClusterNode> IgnitePredicate<T> 
nodeForNodeIds(@Nullable final Collection<UUID>
+        nodeIds) {
+        if (F.isEmpty(nodeIds))
+            return F.alwaysFalse();
+
+        return new ContainsNodeIdsPredicate<>(nodeIds);
+    }
+
+    /**
+     * Get a predicate that evaluates to {@code true} if each of its component 
predicates
+     * evaluates to {@code true}. The components are evaluated in order they 
are supplied.
+     * Evaluation will be stopped as soon as first predicate evaluates to 
{@code false}.
+     * Passed in predicates are NOT copied. If no predicates are passed in the 
returned
+     * predicate will always evaluate to {@code false}.
+     *
+     * @param ps Passed in predicate. If none provided - always-{@code false} 
predicate is
+     *      returned.
+     * @param <T> Type of the free variable, i.e. the element the predicate is 
called on.
+     * @return Predicate that evaluates to {@code true} if each of its 
component predicates
+     *      evaluates to {@code true}.
+     */
+    @SuppressWarnings({"unchecked"})
+    public static <T> IgnitePredicate<T> and(@Nullable final IgnitePredicate<? 
super T>... ps) {

Review Comment:
   Moved it to ClusterGroupAdapter



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to