All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.andyshao.util.function.ExceptionableToIntFunction Maven / Gradle / Ivy

The newest version!
package com.github.andyshao.util.function;

import com.github.andyshao.lang.Convert;
import com.github.andyshao.util.stream.RuntimeExceptionFactory;

import java.util.function.ToIntFunction;

/**
 * 
 * Title:
* Descript:
* Copyright: Copryright(c) Jun 14, 2019
* Encoding: UNIX UTF-8 * * @author Andy.Shao * * @param argument type * @see ToIntFunction */ public interface ExceptionableToIntFunction { /** * apply as int * @param value input * @return int value * @throws Throwable any error */ int applyAsInt(T value) throws Throwable; /** * to {@link ToIntFunction} * @param f exception factory * @return {@link ToIntFunction} * @param data type */ static Convert, ToIntFunction> toIntFunction(RuntimeExceptionFactory f) { return input -> { return t -> { try { return input.applyAsInt(t); } catch (Throwable e) { throw f.build(e); } }; }; } /** * to int function * @return {@link ToIntFunction} * @param data type */ public static Convert, ToIntFunction> toIntFunction() { return toIntFunction(RuntimeExceptionFactory.DEFAULT); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy