List of usage examples for java.util.function BinaryOperator apply
R apply(T t, U u);
From source file:enumj.Enumerator.java
/** * Performs a reduction on enumerated elements using an identity element * and an associative accumulation function and returns the reduced value. * * @param identity starting point for the reduction. * @param accumulator associative {@link BinaryOperator} combining * two enumerated elements.//from w w w . ja va 2 s. co m * @return the reduced value. * @exception IllegalArgumentException <code>accumulator</code> is null. */ public default E reduce(E identity, BinaryOperator<E> accumulator) { Checks.ensureNotNull(accumulator, Messages.NULL_ENUMERATOR_ACCUMULATOR); E result = identity; while (hasNext()) { result = accumulator.apply(result, next()); } return result; }
From source file:org.briljantframework.array.AbstractArray.java
@Override public T reduce(T initial, BinaryOperator<T> accumulator) { for (int i = 0; i < size(); i++) { initial = accumulator.apply(initial, get(i)); }// ww w . j a v a 2 s . c o m return initial; }
From source file:org.briljantframework.array.AbstractComplexArray.java
@Override public ComplexArray combineAssign(ComplexArray array, BinaryOperator<Complex> combine) { array = ShapeUtils.broadcastIfSensible(this, array); Check.dimension(this, array); for (int i = 0; i < size(); i++) { set(i, combine.apply(get(i), array.get(i))); }/*from ww w . j a va 2 s . c o m*/ return this; }
From source file:org.briljantframework.array.AbstractComplexArray.java
@Override public Complex reduce(Complex identity, BinaryOperator<Complex> reduce, UnaryOperator<Complex> map) { for (int i = 0; i < size(); i++) { identity = reduce.apply(map.apply(get(i)), identity); }//from w ww . j a v a2 s .c o m return identity; }