Example usage for java.util.function IntBinaryOperator applyAsInt

List of usage examples for java.util.function IntBinaryOperator applyAsInt

Introduction

In this page you can find the example usage for java.util.function IntBinaryOperator applyAsInt.

Prototype

int applyAsInt(int left, int right);

Source Link

Document

Applies this operator to the given operands.

Usage

From source file:Main.java

public static void main(String[] args) {
    IntBinaryOperator io = (x, y) -> x + y;

    System.out.println(io.applyAsInt(2, 3));

}

From source file:at.gridtec.lambda4j.operator.binary.IntBinaryOperator2.java

/**
 * Calls the given {@link IntBinaryOperator} with the given arguments and returns its result.
 *
 * @param operator The operator to be called
 * @param value1 The first argument to the operator
 * @param value2 The second argument to the operator
 * @return The result from the given {@code IntBinaryOperator2}.
 * @throws NullPointerException If given argument is {@code null}
 */// w  ww.  j a va 2 s.com
static int call(@Nonnull final IntBinaryOperator operator, int value1, int value2) {
    Objects.requireNonNull(operator);
    return operator.applyAsInt(value1, value2);
}

From source file:at.gridtec.lambda4j.operator.binary.ThrowableIntBinaryOperator.java

/**
 * Returns a composed {@link IntBinaryOperator2} that first applies this operator to its input, and then applies the
 * {@code recover} operation if a {@link Throwable} is thrown from this one. The {@code recover} operation is
 * represented by a curried operation which is called with throwable information and same arguments of this
 * operator./* w w  w. ja v a 2  s  . co m*/
 *
 * @param recover The operation to apply if this operator throws a {@code Throwable}
 * @return A composed {@link IntBinaryOperator2} that first applies this operator to its input, and then applies the
 * {@code recover} operation if a {@code Throwable} is thrown from this one.
 * @throws NullPointerException If given argument or the returned enclosing operator is {@code null}
 * @implSpec The implementation checks that the returned enclosing operator from {@code recover} operation is not
 * {@code null}. If it is, then a {@link NullPointerException} with appropriate message is thrown.
 * @implNote If thrown {@code Throwable} is of type {@link Error}, it is thrown as-is and thus not passed to {@code
 * recover} operation.
 */
@Nonnull
default IntBinaryOperator2 recover(
        @Nonnull final Function<? super Throwable, ? extends IntBinaryOperator> recover) {
    Objects.requireNonNull(recover);
    return (value1, value2) -> {
        try {
            return this.applyAsIntThrows(value1, value2);
        } catch (Error e) {
            throw e;
        } catch (Throwable throwable) {
            final IntBinaryOperator operator = recover.apply(throwable);
            Objects.requireNonNull(operator,
                    () -> "recover returned null for " + throwable.getClass() + ": " + throwable.getMessage());
            return operator.applyAsInt(value1, value2);
        }
    };
}

From source file:org.briljantframework.array.AbstractIntArray.java

@Override
public void combineAssign(IntArray array, IntBinaryOperator combine) {
    array = ShapeUtils.broadcastIfSensible(this, array);
    Check.dimension(this, array);
    for (int i = 0; i < size(); i++) {
        set(i, combine.applyAsInt(get(i), array.get(i)));
    }/*w  w w .j ava2 s .c  om*/
}

From source file:org.briljantframework.array.AbstractIntArray.java

@Override
public int reduce(int identity, IntBinaryOperator reduce, IntUnaryOperator map) {
    for (int i = 0, size = size(); i < size; i++) {
        identity = reduce.applyAsInt(map.applyAsInt(get(i)), identity);
    }//from  w w  w .  j  ava 2s.  c  om
    return identity;
}