aboutsummaryrefslogtreecommitdiffstats
path: root/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/filter/NodeListFilter.java
blob: 2b790ff7392905eefd63438185d500e1bbeac183 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision.node.filter;

import com.yahoo.vespa.hosted.provision.Node;

import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;

/**
 * A node filter which matches a particular list of nodes
 *
 * @author bratseth
 */
public class NodeListFilter {

    private NodeListFilter() {}

    private static Predicate<Node> makePredicate(List<Node> nodes) {
        Objects.requireNonNull(nodes, "nodes cannot be null");
        Set<Node> nodesSet = Set.copyOf(nodes);
        return nodesSet::contains;
    }

    public static Predicate<Node> from(Node nodes) {
        return makePredicate(List.of(nodes));
    }

    public static Predicate<Node> from(List<Node> nodes) {
        return makePredicate(nodes);
    }

}