Example usage for java.util.function ToIntBiFunction applyAsInt

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

Introduction

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

Prototype

int applyAsInt(T t, U u);

Source Link

Document

Applies this function to the given arguments.

Usage

From source file:Main.java

public static void main(String[] args) {
    ToIntBiFunction<String, String> i = (x, y) -> Integer.parseInt(x) + Integer.parseInt(x);

    System.out.println(i.applyAsInt("2", "3"));
}

From source file:at.gridtec.lambda4j.function.bi.to.ToIntBiFunction2.java

/**
 * Calls the given {@link ToIntBiFunction} with the given arguments and returns its result.
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param function The function to be called
 * @param t The first argument to the function
 * @param u The second argument to the function
 * @return The result from the given {@code ToIntBiFunction2}.
 * @throws NullPointerException If given argument is {@code null}
 *///from  w  w w  .jav a  2s. com
static <T, U> int call(@Nonnull final ToIntBiFunction<? super T, ? super U> function, T t, U u) {
    Objects.requireNonNull(function);
    return function.applyAsInt(t, u);
}

From source file:at.gridtec.lambda4j.function.bi.to.ThrowableToIntBiFunction.java

/**
 * Returns a composed {@link ToIntBiFunction2} that first applies this function 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
 * function.//from   www.jav  a2s  .c o m
 *
 * @param recover The operation to apply if this function throws a {@code Throwable}
 * @return A composed {@link ToIntBiFunction2} that first applies this function 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 function is {@code null}
 * @implSpec The implementation checks that the returned enclosing function 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 ToIntBiFunction2<T, U> recover(
        @Nonnull final Function<? super Throwable, ? extends ToIntBiFunction<? super T, ? super U>> recover) {
    Objects.requireNonNull(recover);
    return (t, u) -> {
        try {
            return this.applyAsIntThrows(t, u);
        } catch (Error e) {
            throw e;
        } catch (Throwable throwable) {
            final ToIntBiFunction<? super T, ? super U> function = recover.apply(throwable);
            Objects.requireNonNull(function,
                    () -> "recover returned null for " + throwable.getClass() + ": " + throwable.getMessage());
            return function.applyAsInt(t, u);
        }
    };
}