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

net.mintern.functions.nullary.NilToByte Maven / Gradle / Ivy

The newest version!
package net.mintern.functions.nullary;

/**
 * An operation of type {@code () -> byte}.
 *
 */
@FunctionalInterface
public interface NilToByte extends
        net.mintern.functions.nullary.checked.NilToByteE {

    /**
     * Returns a wrapped version of {@code f} that uses {@code toRuntime} to convert any checked
     * {@code Exception} to a {@code RuntimeException}.
     *
     * @param  the {@code Exception} type that the operation may throw
     * @param toRuntime if a checked exception is thrown from
     *      {@link net.mintern.functions.nullary.checked.NilToByteE#call}, then this function
     *      is called in in order to convert it to a {@code RuntimeException}
     * @param f the operation to wrap
     * @return a wrapped version of {@code f} that does not throw checked exceptions
     */
    @SuppressWarnings("unchecked")
    static  NilToByte unchecked(
            java.util.function.Function toRuntime,
            net.mintern.functions.nullary.checked.NilToByteE f) {
        return () -> {
            try {
                return f.call();
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw toRuntime.apply((E) e);
            }
        };
    }

    /**
     * Returns a wrapped version of {@code f} that wraps any checked {@code Exception} with a
     * {@code RuntimeException}.
     *
     * @param  the {@code Exception} type that the operation may throw
     * @param f the operation to wrap
     * @return a wrapped version of {@code f} that does not throw checked exceptions
     */
    static  NilToByte unchecked(
            net.mintern.functions.nullary.checked.NilToByteE f) {
        return unchecked(RuntimeException::new, f);
    }

    /**
     * Returns a wrapped version of {@code f} that wraps any {@code IOException} with an
     * {@link java.io.UncheckedIOException}.
     *
     * @param  the {@code Exception} type that the operation may throw
     * @param f the operation to wrap
     * @return a wrapped version of {@code f} that throws {@code UncheckedIOException} instead of
     *      {@code IOException}
     */
    static  NilToByte uncheckedIO(
            net.mintern.functions.nullary.checked.NilToByteE f) {
        return unchecked(java.io.UncheckedIOException::new, f);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy