diff options
author | Harald Musum <musum@verizonmedia.com> | 2020-07-16 07:27:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-16 07:27:49 +0200 |
commit | 0355cb740fe498abc03861bcb64de5e418c2fa88 (patch) | |
tree | a456fc74ed740d6c5c5fb6ed61f100c09c951c24 /vespajlib/src/main/java/com/yahoo/collections | |
parent | 14c65de9b6b0d7a5dac17aa96109e125c14762b5 (diff) |
Revert "Load platform bundles separately"
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/collections')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/collections/PredicateSplit.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/collections/PredicateSplit.java b/vespajlib/src/main/java/com/yahoo/collections/PredicateSplit.java new file mode 100644 index 00000000000..1b3941df7bf --- /dev/null +++ b/vespajlib/src/main/java/com/yahoo/collections/PredicateSplit.java @@ -0,0 +1,40 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.collections; + +import java.util.List; +import java.util.ArrayList; +import java.util.function.Predicate; + +/** + * Class holding the result of a partition-by-predicate operation. + **/ +public class PredicateSplit<E> { + public final List<E> falseValues; /// list of values where the predicate returned false + public final List<E> trueValues; /// list of values where the predicate returned true + + private PredicateSplit() { + falseValues = new ArrayList<E>(); + trueValues = new ArrayList<E>(); + } + + /** + * Perform a partition-by-predicate operation. + * Each value in the input is tested by the predicate and + * added to either the falseValues list or the trueValues list. + * @param collection The input collection. + * @param predicate A test for selecting the target list. + * @return Two lists bundled in an object. + **/ + public static <V> PredicateSplit<V> partition(Iterable<V> collection, Predicate<? super V> predicate) + { + PredicateSplit<V> r = new PredicateSplit<V>(); + for (V value : collection) { + if (predicate.test(value)) { + r.trueValues.add(value); + } else { + r.falseValues.add(value); + } + } + return r; + } +} |