Example usage for java.util.function LongBinaryOperator applyAsLong

List of usage examples for java.util.function LongBinaryOperator applyAsLong

Introduction

In this page you can find the example usage for java.util.function LongBinaryOperator applyAsLong.

Prototype

long applyAsLong(long left, long right);

Source Link

Document

Applies this operator to the given operands.

Usage

From source file:Main.java

public static void main(String[] args) {
    LongBinaryOperator i = (x, y) -> x / y;
    System.out.println(i.applyAsLong(Long.MAX_VALUE, Long.MAX_VALUE));
}

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

/**
 * Calls the given {@link LongBinaryOperator} 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 LongBinaryOperator2}.
 * @throws NullPointerException If given argument is {@code null}
 *//*ww  w  .j a  va  2s  . co  m*/
static long call(@Nonnull final LongBinaryOperator operator, long value1, long value2) {
    Objects.requireNonNull(operator);
    return operator.applyAsLong(value1, value2);
}

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

/**
 * Returns a composed {@link LongBinaryOperator2} 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.//from   w w  w  .ja  va2s . c  o  m
 *
 * @param recover The operation to apply if this operator throws a {@code Throwable}
 * @return A composed {@link LongBinaryOperator2} 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 LongBinaryOperator2 recover(
        @Nonnull final Function<? super Throwable, ? extends LongBinaryOperator> recover) {
    Objects.requireNonNull(recover);
    return (value1, value2) -> {
        try {
            return this.applyAsLongThrows(value1, value2);
        } catch (Error e) {
            throw e;
        } catch (Throwable throwable) {
            final LongBinaryOperator operator = recover.apply(throwable);
            Objects.requireNonNull(operator,
                    () -> "recover returned null for " + throwable.getClass() + ": " + throwable.getMessage());
            return operator.applyAsLong(value1, value2);
        }
    };
}

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

@Override
public LongArray combineAssign(LongArray array, LongBinaryOperator combine) {
    array = ShapeUtils.broadcastIfSensible(this, array);
    Check.dimension(this, array);
    for (int i = 0; i < size(); i++) {
        set(i, combine.applyAsLong(get(i), array.get(i)));
    }/* www.ja v a 2 s  .c om*/
    return this;
}

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

@Override
public long reduce(long identity, LongBinaryOperator reduce, LongUnaryOperator map) {
    for (int i = 0; i < size(); i++) {
        identity = reduce.applyAsLong(map.applyAsLong(get(i)), identity);
    }/*from  ww w  . jav a2  s.  c  o  m*/
    return identity;
}