List of usage examples for java.util Vector.Builder addAll
public boolean addAll(Collection<? extends E> c)
From source file:org.briljantframework.data.Collectors.java
/** * Performs a transformation operation, mapping each element to a new value, adding it to the * {@code Vector.Builder} finishing it constructs a new {@code Vector}. * * @param supplier supply the vector builder * @param function the mapper/*from w w w .ja va2s. c o m*/ * @param <T> the input type * @param <O> the output type * @return a transformation aggregator */ public static <T, O> Collector<T, ?, Vector> map(Supplier<Vector.Builder> supplier, Function<? super T, ? extends O> function) { return Collector.of(supplier, (acc, v) -> acc.add(function.apply(v)), (Vector.Builder left, Vector.Builder right) -> { left.addAll(right); return left; }, Vector.Builder::build); }
From source file:org.briljantframework.data.Collectors.java
/** * Returns an aggregator that filter values. * * @param supplier the vector builder// ww w .jav a 2s . c o m * @param predicate the predicate. If {@code true} include value. * @param <T> the input type * @return a filtering aggregator */ public static <T> Collector<T, ?, Vector> filter(Supplier<Vector.Builder> supplier, Predicate<T> predicate) { return Collector.of(supplier, (acc, v) -> { if (predicate.test(v)) { acc.add(v); } }, (Vector.Builder left, Vector.Builder right) -> { left.addAll(right); return left; }, Vector.Builder::build); }
From source file:org.briljantframework.data.Collectors.java
/** * @param copies the number of copies of each element * @return an aggregator that repeats each value {@code copies} times. *///from w ww . ja va 2 s.c om public static <T> Collector<T, ?, Vector> each(Supplier<Vector.Builder> vb, int copies) { return Collector.of(vb, (acc, v) -> { for (int i = 0; i < copies; i++) { acc.add(v); } }, (Vector.Builder left, Vector.Builder right) -> { left.addAll(right); return left; }, Vector.Builder::build); }
From source file:org.briljantframework.data.Collectors.java
public static <T> Collector<T, ?, Vector> repeat(Supplier<Vector.Builder> vb, int copies) { return Collector.of(vb, Vector.Builder::add, (Vector.Builder left, Vector.Builder right) -> { left.addAll(right); return left; }, (v) -> {/*from w w w . j ava2 s . c om*/ Vector temp = v.getView(); int size = temp.size(); for (int i = 1; i < copies; i++) { for (int j = 0; j < size; j++) { v.add(temp, j); } } return v.build(); }); }
From source file:org.briljantframework.data.vector.Vector.java
/** * Construct a vector of values. The type of vector is inferred from the values. * * @param array the values//from w w w . j ava2 s. c om * @return a new vector */ @SafeVarargs static <T> Vector of(T... array) { Vector.Builder builder = Vector.Builder.of(array.getClass().getComponentType()); builder.addAll(array); return builder.build(); }