/** * Returns a {@code Collector} which produces a boolean array containing the * results of applying the given predicate to the input elements, in * encounter order. * * @param <T> the type of the input elements * @param predicate a non-interfering, stateless predicate to apply to each * input element. The result values of this predicate are collected * to the resulting boolean array. * @return a {@code Collector} which collects the results of the predicate * function to the boolean array, in encounter order. * @since 0.3.8 */ public static <T> Collector<T, ?, boolean[]> toBooleanArray(Predicate<T> predicate) { return PartialCollector.booleanArray().asRef((box, t) -> { if (predicate.test(t)) box.a.set(box.b); box.b = StrictMath.addExact(box.b, 1); }); }
/** * Returns an {@code IntCollector} which produces a boolean array containing * the results of applying the given predicate to the input elements, in * encounter order. * * @param predicate a non-interfering, stateless predicate to apply to each * input element. The result values of this predicate are collected * to the resulting boolean array. * @return an {@code IntCollector} which collects the results of the * predicate function to the boolean array, in encounter order. * @since 0.3.8 */ static IntCollector<?, boolean[]> toBooleanArray(IntPredicate predicate) { return PartialCollector.booleanArray().asInt((box, t) -> { if (predicate.test(t)) box.a.set(box.b); box.b = StrictMath.addExact(box.b, 1); }); } }
/** * Returns a {@code LongCollector} which produces a boolean array containing * the results of applying the given predicate to the input elements, in * encounter order. * * @param predicate a non-interfering, stateless predicate to apply to each * input element. The result values of this predicate are collected * to the resulting boolean array. * @return a {@code LongCollector} which collects the results of the * predicate function to the boolean array, in encounter order. * @since 0.3.8 */ static LongCollector<?, boolean[]> toBooleanArray(LongPredicate predicate) { return PartialCollector.booleanArray().asLong((box, t) -> { if (predicate.test(t)) box.a.set(box.b); box.b = StrictMath.addExact(box.b, 1); }); } }
/** * Returns a {@code DoubleCollector} which produces a boolean array * containing the results of applying the given predicate to the input * elements, in encounter order. * * @param predicate a non-interfering, stateless predicate to apply to each * input element. The result values of this predicate are collected * to the resulting boolean array. * @return a {@code DoubleCollector} which collects the results of the * predicate function to the boolean array, in encounter order. * @since 0.3.8 */ static DoubleCollector<?, boolean[]> toBooleanArray(DoublePredicate predicate) { return PartialCollector.booleanArray().asDouble((box, t) -> { if (predicate.test(t)) box.a.set(box.b); box.b = StrictMath.addExact(box.b, 1); }); } }