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

com.landawn.abacus.util.Throwables Maven / Gradle / Ivy

Go to download

A general programming library in Java/Android. It's easy to learn and simple to use with concise and powerful APIs.

There is a newer version: 5.3.16
Show newest version
/*
 * Copyright (C) 2019 HaiYang Li
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.landawn.abacus.util;

/**
 * Catch checked exception and convert it to RuntimeException.
 *
 * @author Haiyang Li
 * @param 
 * @since 0.8
 */
public final class Throwables {

    private Throwables() {
        // Singleton for utility class.
    }

    /**
     *
     * @param cmd
     * @throws RuntimeException if some error happens
     */
    public static void run(final Throwables.Runnable cmd) {
        try {
            cmd.run();
        } catch (Throwable e) {
            throw ExceptionUtil.toRuntimeException(e);
        }
    }

    /**
     *
     * @param cmd
     * @param actionOnError
     */
    public static void run(final Throwables.Runnable cmd,
            final com.landawn.abacus.util.function.Consumer actionOnError) {
        N.checkArgNotNull(actionOnError);

        try {
            cmd.run();
        } catch (Throwable e) {
            actionOnError.accept(e);
        }
    }

    /**
     *
     * @param 
     * @param cmd
     * @return
     * @throws RuntimeException if some error happens
     */
    public static  R call(final Throwables.Callable cmd) {
        try {
            return cmd.call();
        } catch (Throwable e) {
            throw ExceptionUtil.toRuntimeException(e);
        }
    }

    /**
     *
     * @param 
     * @param cmd
     * @param actionOnError
     * @return
     */
    public static  R call(final Throwables.Callable cmd,
            final com.landawn.abacus.util.function.Function actionOnError) {
        N.checkArgNotNull(actionOnError);

        try {
            return cmd.call();
        } catch (Throwable e) {
            return actionOnError.apply(e);
        }
    }

    /**
     *
     * @param 
     * @param cmd
     * @param supplier
     * @return
     */
    public static  R call(final Throwables.Callable cmd, final com.landawn.abacus.util.function.Supplier supplier) {
        N.checkArgNotNull(supplier);

        try {
            return cmd.call();
        } catch (Throwable e) {
            return supplier.get();
        }
    }

    /**
     *
     * @param 
     * @param cmd
     * @param defaultValue
     * @return
     */
    public static  R call(final Throwables.Callable cmd, final R defaultValue) {
        try {
            return cmd.call();
        } catch (Throwable e) {
            return defaultValue;
        }
    }

    /**
     *
     * @param 
     * @param cmd
     * @param predicate
     * @param supplier
     * @return
     * @throws RuntimeException if some error happens and predicate return false.
     */
    public static  R call(final Throwables.Callable cmd,
            final com.landawn.abacus.util.function.Predicate predicate, final com.landawn.abacus.util.function.Supplier supplier) {
        N.checkArgNotNull(predicate);
        N.checkArgNotNull(supplier);

        try {
            return cmd.call();
        } catch (Throwable e) {
            if (predicate.test(e)) {
                return supplier.get();
            } else {
                throw ExceptionUtil.toRuntimeException(e);
            }
        }
    }

    /**
     *
     * @param 
     * @param cmd
     * @param predicate
     * @param defaultValue
     * @return
     * @throws RuntimeException if some error happens and predicate return false.
     */
    public static  R call(final Throwables.Callable cmd,
            final com.landawn.abacus.util.function.Predicate predicate, final R defaultValue) {
        N.checkArgNotNull(predicate);

        try {
            return cmd.call();
        } catch (Throwable e) {
            if (predicate.test(e)) {
                return defaultValue;
            } else {
                throw ExceptionUtil.toRuntimeException(e);
            }
        }
    }

    /**
     * The Interface Runnable.
     *
     * @param 
     */
    public interface Runnable {

        /**
         *
         * @throws E the e
         */
        void run() throws E;
    }

    /**
     * The Interface Callable.
     *
     * @param 
     * @param 
     */
    public interface Callable {

        /**
         *
         * @return
         * @throws E the e
         */
        R call() throws E;
    }

    /**
     * The Interface Supplier.
     *
     * @param 
     * @param 
     */
    public interface Supplier {

        /**
         *
         * @return
         * @throws E the e
         */
        T get() throws E;
    }

    /**
     * The Interface BooleanSupplier.
     *
     * @param 
     */
    public interface BooleanSupplier {

        /**
         * Gets the as boolean.
         *
         * @return
         * @throws E the e
         */
        boolean getAsBoolean() throws E;
    }

    /**
     * The Interface CharSupplier.
     *
     * @param 
     */
    public interface CharSupplier {

        /**
         * Gets the as char.
         *
         * @return
         * @throws E the e
         */
        char getAsChar() throws E;
    }

    /**
     * The Interface ByteSupplier.
     *
     * @param 
     */
    public interface ByteSupplier {

        /**
         * Gets the as byte.
         *
         * @return
         * @throws E the e
         */
        byte getAsByte() throws E;
    }

    /**
     * The Interface ShortSupplier.
     *
     * @param 
     */
    public interface ShortSupplier {

        /**
         * Gets the as short.
         *
         * @return
         * @throws E the e
         */
        short getAsShort() throws E;
    }

    /**
     * The Interface IntSupplier.
     *
     * @param 
     */
    public interface IntSupplier {

        /**
         * Gets the as int.
         *
         * @return
         * @throws E the e
         */
        int getAsInt() throws E;
    }

    /**
     * The Interface LongSupplier.
     *
     * @param 
     */
    public interface LongSupplier {

        /**
         * Gets the as long.
         *
         * @return
         * @throws E the e
         */
        long getAsLong() throws E;
    }

    /**
     * The Interface FloatSupplier.
     *
     * @param 
     */
    public interface FloatSupplier {

        /**
         * Gets the as float.
         *
         * @return
         * @throws E the e
         */
        float getAsFloat() throws E;
    }

    /**
     * The Interface DoubleSupplier.
     *
     * @param 
     */
    public interface DoubleSupplier {

        /**
         * Gets the as double.
         *
         * @return
         * @throws E the e
         */
        double getAsDouble() throws E;
    }

    /**
     * The Interface Predicate.
     *
     * @param 
     * @param 
     */
    public interface Predicate {

        /**
         *
         * @param t
         * @return
         * @throws E the e
         */
        boolean test(T t) throws E;
    }

    /**
     * The Interface BiPredicate.
     *
     * @param 
     * @param 
     * @param 
     */
    public interface BiPredicate {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        boolean test(T t, U u) throws E;
    }

    /**
     * The Interface TriPredicate.
     *
     * @param 
     * @param 
     * @param 
     * @param 
     */
    public interface TriPredicate {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        boolean test(A a, B b, C c) throws E;
    }

    /**
     * The Interface QuadPredicate.
     *
     * @param 
     * @param 
     * @param 
     * @param 
     * @param 
     */
    public interface QuadPredicate {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @param d
         * @return
         * @throws E the e
         */
        boolean test(A a, B b, C c, D d) throws E;
    }

    /**
     * The Interface Function.
     *
     * @param 
     * @param 
     * @param 
     */
    public interface Function {

        /**
         *
         * @param t
         * @return
         * @throws E the e
         */
        R apply(T t) throws E;
    }

    /**
     * The Interface BiFunction.
     *
     * @param 
     * @param 
     * @param 
     * @param 
     */
    public interface BiFunction {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        R apply(T t, U u) throws E;
    }

    /**
     * The Interface TriFunction.
     *
     * @param 
     * @param 
     * @param 
     * @param 
     * @param 
     */
    public interface TriFunction {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        R apply(A a, B b, C c) throws E;
    }

    /**
     * The Interface QuadFunction.
     *
     * @param 
     * @param 
     * @param 
     * @param 
     * @param 
     * @param 
     */
    public interface QuadFunction {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @param d
         * @return
         * @throws E the e
         */
        R apply(A a, B b, C c, D d) throws E;
    }

    /**
     * The Interface Consumer.
     *
     * @param 
     * @param 
     */
    public interface Consumer {

        /**
         *
         * @param t
         * @throws E the e
         */
        void accept(T t) throws E;
    }

    /**
     * The Interface BiConsumer.
     *
     * @param 
     * @param 
     * @param 
     */
    public interface BiConsumer {

        /**
         *
         * @param t
         * @param u
         * @throws E the e
         */
        void accept(T t, U u) throws E;
    }

    /**
     * The Interface TriConsumer.
     *
     * @param 
     * @param 
     * @param 
     * @param 
     */
    public interface TriConsumer {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @throws E the e
         */
        void accept(A a, B b, C c) throws E;
    }

    /**
     * The Interface QuadConsumer.
     *
     * @param 
     * @param 
     * @param 
     * @param 
     * @param 
     */
    public interface QuadConsumer {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @param d
         * @throws E the e
         */
        void accept(A a, B b, C c, D d) throws E;
    }

    /**
     * The Interface IndexedConsumer.
     *
     * @param 
     * @param 
     */
    public interface IndexedConsumer {

        /**
         *
         * @param idx
         * @param e
         * @throws E the e
         */
        void accept(int idx, T e) throws E;
    }

    /**
     * The Interface IndexedBiConsumer.
     *
     * @param 
     * @param 
     * @param 
     */
    public interface IndexedBiConsumer {

        /**
         *
         * @param u
         * @param idx
         * @param e
         * @throws E the e
         */
        void accept(U u, int idx, T e) throws E;
    }

    /**
     * The Interface IndexedFunction.
     *
     * @param 
     * @param 
     * @param 
     */
    public interface IndexedFunction {

        /**
         *
         * @param idx
         * @param e
         * @return
         * @throws E the e
         */
        R apply(int idx, T e) throws E;
    }

    /**
     * The Interface IndexedBiFunction.
     *
     * @param 
     * @param 
     * @param 
     * @param 
     */
    public interface IndexedBiFunction {

        /**
         *
         * @param u
         * @param idx
         * @param e
         * @return
         * @throws E the e
         */
        R apply(U u, int idx, T e) throws E;
    }

    /**
     * The Interface IndexedPredicate.
     *
     * @param 
     * @param 
     */
    public interface IndexedPredicate {

        /**
         *
         * @param idx
         * @param e
         * @return
         * @throws E the e
         */
        boolean test(int idx, T e) throws E;
    }

    /**
     * The Interface IndexedBiPredicate.
     *
     * @param 
     * @param 
     * @param 
     */
    public interface IndexedBiPredicate {

        /**
         *
         * @param u
         * @param idx
         * @param e
         * @return
         * @throws E the e
         */
        boolean test(U u, int idx, T e) throws E;
    }

    /**
     * The Interface IndexedBooleanConsumer.
     *
     * @param 
     */
    public interface IndexedBooleanConsumer {

        /**
         *
         * @param idx
         * @param e
         * @throws E the e
         */
        void accept(int idx, boolean e) throws E;
    }

    /**
     * The Interface IndexedCharConsumer.
     *
     * @param 
     */
    public interface IndexedCharConsumer {

        /**
         *
         * @param idx
         * @param e
         * @throws E the e
         */
        void accept(int idx, char e) throws E;
    }

    /**
     * The Interface IndexedByteConsumer.
     *
     * @param 
     */
    public interface IndexedByteConsumer {

        /**
         *
         * @param idx
         * @param e
         * @throws E the e
         */
        void accept(int idx, byte e) throws E;
    }

    /**
     * The Interface IndexedShortConsumer.
     *
     * @param 
     */
    public interface IndexedShortConsumer {

        /**
         *
         * @param idx
         * @param e
         * @throws E the e
         */
        void accept(int idx, short e) throws E;
    }

    /**
     * The Interface IndexedIntConsumer.
     *
     * @param 
     */
    public interface IndexedIntConsumer {

        /**
         *
         * @param idx
         * @param e
         * @throws E the e
         */
        void accept(int idx, int e) throws E;
    }

    /**
     * The Interface IndexedLongConsumer.
     *
     * @param 
     */
    public interface IndexedLongConsumer {

        /**
         *
         * @param idx
         * @param e
         * @throws E the e
         */
        void accept(int idx, long e) throws E;
    }

    /**
     * The Interface IndexedFloatConsumer.
     *
     * @param 
     */
    public interface IndexedFloatConsumer {

        /**
         *
         * @param idx
         * @param e
         * @throws E the e
         */
        void accept(int idx, float e) throws E;
    }

    /**
     * The Interface IndexedDoubleConsumer.
     *
     * @param 
     */
    public interface IndexedDoubleConsumer {

        /**
         *
         * @param idx
         * @param e
         * @throws E the e
         */
        void accept(int idx, double e) throws E;
    }

    /**
     * The Interface BooleanPredicate.
     *
     * @param 
     */
    public interface BooleanPredicate {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        boolean test(boolean value) throws E;
    }

    /**
     * The Interface BooleanFunction.
     *
     * @param 
     * @param 
     */
    public interface BooleanFunction {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        R apply(boolean value) throws E;
    }

    /**
     * The Interface BooleanConsumer.
     *
     * @param 
     */
    public interface BooleanConsumer {

        /**
         *
         * @param t
         * @throws E the e
         */
        void accept(boolean t) throws E;
    }

    /**
     * The Interface CharPredicate.
     *
     * @param 
     */
    public interface CharPredicate {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        boolean test(char value) throws E;
    }

    /**
     * The Interface CharFunction.
     *
     * @param 
     * @param 
     */
    public interface CharFunction {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        R apply(char value) throws E;
    }

    /**
     * The Interface CharConsumer.
     *
     * @param 
     */
    public interface CharConsumer {

        /**
         *
         * @param t
         * @throws E the e
         */
        void accept(char t) throws E;
    }

    /**
     * The Interface BytePredicate.
     *
     * @param 
     */
    public interface BytePredicate {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        boolean test(byte value) throws E;
    }

    /**
     * The Interface ByteFunction.
     *
     * @param 
     * @param 
     */
    public interface ByteFunction {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        R apply(byte value) throws E;
    }

    /**
     * The Interface ByteConsumer.
     *
     * @param 
     */
    public interface ByteConsumer {

        /**
         *
         * @param t
         * @throws E the e
         */
        void accept(byte t) throws E;
    }

    /**
     * The Interface ShortPredicate.
     *
     * @param 
     */
    public interface ShortPredicate {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        boolean test(short value) throws E;
    }

    /**
     * The Interface ShortFunction.
     *
     * @param 
     * @param 
     */
    public interface ShortFunction {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        R apply(short value) throws E;
    }

    /**
     * The Interface ShortConsumer.
     *
     * @param 
     */
    public interface ShortConsumer {

        /**
         *
         * @param t
         * @throws E the e
         */
        void accept(short t) throws E;
    }

    /**
     * The Interface IntPredicate.
     *
     * @param 
     */
    public interface IntPredicate {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        boolean test(int value) throws E;
    }

    /**
     * The Interface IntFunction.
     *
     * @param 
     * @param 
     */
    public interface IntFunction {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        R apply(int value) throws E;
    }

    /**
     * The Interface IntConsumer.
     *
     * @param 
     */
    public interface IntConsumer {

        /**
         *
         * @param t
         * @throws E the e
         */
        void accept(int t) throws E;
    }

    /**
     * The Interface LongPredicate.
     *
     * @param 
     */
    public interface LongPredicate {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        boolean test(long value) throws E;
    }

    /**
     * The Interface LongFunction.
     *
     * @param 
     * @param 
     */
    public interface LongFunction {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        R apply(long value) throws E;
    }

    /**
     * The Interface LongConsumer.
     *
     * @param 
     */
    public interface LongConsumer {

        /**
         *
         * @param t
         * @throws E the e
         */
        void accept(long t) throws E;
    }

    /**
     * The Interface FloatPredicate.
     *
     * @param 
     */
    public interface FloatPredicate {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        boolean test(float value) throws E;
    }

    /**
     * The Interface FloatFunction.
     *
     * @param 
     * @param 
     */
    public interface FloatFunction {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        R apply(float value) throws E;
    }

    /**
     * The Interface FloatConsumer.
     *
     * @param 
     */
    public interface FloatConsumer {

        /**
         *
         * @param t
         * @throws E the e
         */
        void accept(float t) throws E;
    }

    /**
     * The Interface DoublePredicate.
     *
     * @param 
     */
    public interface DoublePredicate {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        boolean test(double value) throws E;
    }

    /**
     * The Interface DoubleFunction.
     *
     * @param 
     * @param 
     */
    public interface DoubleFunction {

        /**
         *
         * @param value
         * @return
         * @throws E the e
         */
        R apply(double value) throws E;
    }

    /**
     * The Interface DoubleConsumer.
     *
     * @param 
     */
    public interface DoubleConsumer {

        /**
         *
         * @param t
         * @throws E the e
         */
        void accept(double t) throws E;
    }

    /**
     * The Interface ToBooleanFunction.
     *
     * @param 
     * @param 
     */
    public interface ToBooleanFunction {

        /**
         * Apply as boolean.
         *
         * @param t
         * @return
         * @throws E the e
         */
        boolean applyAsBoolean(T t) throws E;
    }

    /**
     * The Interface ToCharFunction.
     *
     * @param 
     * @param 
     */
    public interface ToCharFunction {

        /**
         * Apply as char.
         *
         * @param t
         * @return
         * @throws E the e
         */
        char applyAsChar(T t) throws E;
    }

    /**
     * The Interface ToByteFunction.
     *
     * @param 
     * @param 
     */
    public interface ToByteFunction {

        /**
         * Apply as byte.
         *
         * @param t
         * @return
         * @throws E the e
         */
        byte applyAsByte(T t) throws E;
    }

    /**
     * The Interface ToShortFunction.
     *
     * @param 
     * @param 
     */
    public interface ToShortFunction {

        /**
         * Apply as short.
         *
         * @param t
         * @return
         * @throws E the e
         */
        short applyAsShort(T t) throws E;
    }

    /**
     * The Interface ToIntFunction.
     *
     * @param 
     * @param 
     */
    public interface ToIntFunction {

        /**
         * Apply as int.
         *
         * @param t
         * @return
         * @throws E the e
         */
        int applyAsInt(T t) throws E;
    }

    /**
     * The Interface ToLongFunction.
     *
     * @param 
     * @param 
     */
    public interface ToLongFunction {

        /**
         * Apply as long.
         *
         * @param t
         * @return
         * @throws E the e
         */
        long applyAsLong(T t) throws E;
    }

    /**
     * The Interface ToFloatFunction.
     *
     * @param 
     * @param 
     */
    public interface ToFloatFunction {

        /**
         * Apply as float.
         *
         * @param t
         * @return
         * @throws E the e
         */
        float applyAsFloat(T t) throws E;
    }

    /**
     * The Interface ToDoubleFunction.
     *
     * @param 
     * @param 
     */
    public interface ToDoubleFunction {

        /**
         * Apply as double.
         *
         * @param t
         * @return
         * @throws E the e
         */
        double applyAsDouble(T t) throws E;
    }

    /**
     * The Interface UnaryOperator.
     *
     * @param 
     * @param 
     */
    public interface UnaryOperator extends Function {
    }

    /**
     * The Interface BinaryOperator.
     *
     * @param 
     * @param 
     */
    public interface BinaryOperator extends BiFunction {
    }

    /**
     * The Interface TernaryOperator.
     *
     * @param 
     * @param 
     */
    public interface TernaryOperator extends BiFunction {
    }

    /**
     * The Interface BooleanUnaryOperator.
     *
     * @param 
     */
    public interface BooleanUnaryOperator {

        /**
         * Apply as boolean.
         *
         * @param operand
         * @return
         * @throws E the e
         */
        boolean applyAsBoolean(boolean operand) throws E;
    }

    /**
     * The Interface CharUnaryOperator.
     *
     * @param 
     */
    public interface CharUnaryOperator {

        /**
         * Apply as char.
         *
         * @param operand
         * @return
         * @throws E the e
         */
        char applyAsChar(char operand) throws E;
    }

    /**
     * The Interface ByteUnaryOperator.
     *
     * @param 
     */
    public interface ByteUnaryOperator {

        /**
         * Apply as byte.
         *
         * @param operand
         * @return
         * @throws E the e
         */
        byte applyAsByte(byte operand) throws E;
    }

    /**
     * The Interface ShortUnaryOperator.
     *
     * @param 
     */
    public interface ShortUnaryOperator {

        /**
         * Apply as short.
         *
         * @param operand
         * @return
         * @throws E the e
         */
        short applyAsShort(short operand) throws E;
    }

    /**
     * The Interface IntUnaryOperator.
     *
     * @param 
     */
    public interface IntUnaryOperator {

        /**
         * Apply as int.
         *
         * @param operand
         * @return
         * @throws E the e
         */
        int applyAsInt(int operand) throws E;
    }

    /**
     * The Interface LongUnaryOperator.
     *
     * @param 
     */
    public interface LongUnaryOperator {

        /**
         * Apply as long.
         *
         * @param operand
         * @return
         * @throws E the e
         */
        long applyAsLong(long operand) throws E;
    }

    /**
     * The Interface FloatUnaryOperator.
     *
     * @param 
     */
    public interface FloatUnaryOperator {

        /**
         * Apply as float.
         *
         * @param operand
         * @return
         * @throws E the e
         */
        float applyAsFloat(float operand) throws E;
    }

    /**
     * The Interface DoubleUnaryOperator.
     *
     * @param 
     */
    public interface DoubleUnaryOperator {

        /**
         * Apply as double.
         *
         * @param operand
         * @return
         * @throws E the e
         */
        double applyAsDouble(double operand) throws E;
    }

    /**
     * The Interface BooleanBinaryOperator.
     *
     * @param 
     */
    public interface BooleanBinaryOperator {

        /**
         * Apply as boolean.
         *
         * @param left
         * @param right
         * @return
         * @throws E the e
         */
        boolean applyAsBoolean(boolean left, boolean right) throws E;
    }

    /**
     * The Interface CharBinaryOperator.
     *
     * @param 
     */
    public interface CharBinaryOperator {

        /**
         * Apply as char.
         *
         * @param left
         * @param right
         * @return
         * @throws E the e
         */
        char applyAsChar(char left, char right) throws E;
    }

    /**
     * The Interface ByteBinaryOperator.
     *
     * @param 
     */
    public interface ByteBinaryOperator {

        /**
         * Apply as byte.
         *
         * @param left
         * @param right
         * @return
         * @throws E the e
         */
        byte applyAsByte(byte left, byte right) throws E;
    }

    /**
     * The Interface ShortBinaryOperator.
     *
     * @param 
     */
    public interface ShortBinaryOperator {

        /**
         * Apply as short.
         *
         * @param left
         * @param right
         * @return
         * @throws E the e
         */
        short applyAsShort(short left, short right) throws E;
    }

    /**
     * The Interface IntBinaryOperator.
     *
     * @param 
     */
    public interface IntBinaryOperator {

        /**
         * Apply as int.
         *
         * @param left
         * @param right
         * @return
         * @throws E the e
         */
        int applyAsInt(int left, int right) throws E;
    }

    /**
     * The Interface LongBinaryOperator.
     *
     * @param 
     */
    public interface LongBinaryOperator {

        /**
         * Apply as long.
         *
         * @param left
         * @param right
         * @return
         * @throws E the e
         */
        long applyAsLong(long left, long right) throws E;
    }

    /**
     * The Interface FloatBinaryOperator.
     *
     * @param 
     */
    public interface FloatBinaryOperator {

        /**
         * Apply as float.
         *
         * @param left
         * @param right
         * @return
         * @throws E the e
         */
        float applyAsFloat(float left, float right) throws E;
    }

    /**
     * The Interface DoubleBinaryOperator.
     *
     * @param 
     */
    public interface DoubleBinaryOperator {

        /**
         * Apply as double.
         *
         * @param left
         * @param right
         * @return
         * @throws E the e
         */
        double applyAsDouble(double left, double right) throws E;
    }

    /**
     * The Interface BooleanTernaryOperator.
     *
     * @param 
     */
    public interface BooleanTernaryOperator {

        /**
         * Apply as boolean.
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        boolean applyAsBoolean(boolean a, boolean b, boolean c) throws E;
    }

    /**
     * The Interface CharTernaryOperator.
     *
     * @param 
     */
    public interface CharTernaryOperator {

        /**
         * Apply as char.
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        char applyAsChar(char a, char b, char c) throws E;
    }

    /**
     * The Interface ByteTernaryOperator.
     *
     * @param 
     */
    public interface ByteTernaryOperator {

        /**
         * Apply as byte.
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        byte applyAsByte(byte a, byte b, byte c) throws E;
    }

    /**
     * The Interface ShortTernaryOperator.
     *
     * @param 
     */
    public interface ShortTernaryOperator {

        /**
         * Apply as short.
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        short applyAsShort(short a, short b, short c) throws E;
    }

    /**
     * The Interface IntTernaryOperator.
     *
     * @param 
     */
    public interface IntTernaryOperator {

        /**
         * Apply as int.
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        int applyAsInt(int a, int b, int c) throws E;
    }

    /**
     * The Interface LongTernaryOperator.
     *
     * @param 
     */
    public interface LongTernaryOperator {

        /**
         * Apply as long.
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        long applyAsLong(long a, long b, long c) throws E;
    }

    /**
     * The Interface FloatTernaryOperator.
     *
     * @param 
     */
    public interface FloatTernaryOperator {

        /**
         * Apply as float.
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        float applyAsFloat(float a, float b, float c) throws E;
    }

    /**
     * The Interface DoubleTernaryOperator.
     *
     * @param 
     */
    public interface DoubleTernaryOperator {

        /**
         * Apply as double.
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        double applyAsDouble(double a, double b, double c) throws E;
    }

    /**
     * The Interface BooleanBiPredicate.
     *
     * @param 
     */
    public interface BooleanBiPredicate {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        boolean test(boolean t, boolean u) throws E;
    }

    /**
     * The Interface CharBiPredicate.
     *
     * @param 
     */
    public interface CharBiPredicate {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        boolean test(char t, char u) throws E;
    }

    /**
     * The Interface ByteBiPredicate.
     *
     * @param 
     */
    public interface ByteBiPredicate {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        boolean test(byte t, byte u) throws E;
    }

    /**
     * The Interface ShortBiPredicate.
     *
     * @param 
     */
    public interface ShortBiPredicate {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        boolean test(short t, short u) throws E;
    }

    /**
     * The Interface IntBiPredicate.
     *
     * @param 
     */
    public interface IntBiPredicate {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        boolean test(int t, int u) throws E;
    }

    /**
     * The Interface LongBiPredicate.
     *
     * @param 
     */
    public interface LongBiPredicate {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        boolean test(long t, long u) throws E;
    }

    /**
     * The Interface FloatBiPredicate.
     *
     * @param 
     */
    public interface FloatBiPredicate {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        boolean test(float t, float u) throws E;
    }

    /**
     * The Interface DoubleBiPredicate.
     *
     * @param 
     */
    public interface DoubleBiPredicate {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        boolean test(double t, double u) throws E;
    }

    /**
     * The Interface BooleanBiFunction.
     *
     * @param 
     * @param 
     */
    public interface BooleanBiFunction {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        R apply(boolean t, boolean u) throws E;
    }

    /**
     * The Interface CharBiFunction.
     *
     * @param 
     * @param 
     */
    public interface CharBiFunction {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        R apply(char t, char u) throws E;
    }

    /**
     * The Interface ByteBiFunction.
     *
     * @param 
     * @param 
     */
    public interface ByteBiFunction {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        R apply(byte t, byte u) throws E;
    }

    /**
     * The Interface ShortBiFunction.
     *
     * @param 
     * @param 
     */
    public interface ShortBiFunction {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        R apply(short t, short u) throws E;
    }

    /**
     * The Interface IntBiFunction.
     *
     * @param 
     * @param 
     */
    public interface IntBiFunction {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        R apply(int t, int u) throws E;
    }

    /**
     * The Interface LongBiFunction.
     *
     * @param 
     * @param 
     */
    public interface LongBiFunction {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        R apply(long t, long u) throws E;
    }

    /**
     * The Interface FloatBiFunction.
     *
     * @param 
     * @param 
     */
    public interface FloatBiFunction {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        R apply(float t, float u) throws E;
    }

    /**
     * The Interface DoubleBiFunction.
     *
     * @param 
     * @param 
     */
    public interface DoubleBiFunction {

        /**
         *
         * @param t
         * @param u
         * @return
         * @throws E the e
         */
        R apply(double t, double u) throws E;
    }

    /**
     * The Interface BooleanBiConsumer.
     *
     * @param 
     */
    public interface BooleanBiConsumer {

        /**
         *
         * @param t
         * @param u
         * @throws E the e
         */
        void accept(boolean t, boolean u) throws E;
    }

    /**
     * The Interface CharBiConsumer.
     *
     * @param 
     */
    public interface CharBiConsumer {

        /**
         *
         * @param t
         * @param u
         * @throws E the e
         */
        void accept(char t, char u) throws E;
    }

    /**
     * The Interface ByteBiConsumer.
     *
     * @param 
     */
    public interface ByteBiConsumer {

        /**
         *
         * @param t
         * @param u
         * @throws E the e
         */
        void accept(byte t, byte u) throws E;
    }

    /**
     * The Interface ShortBiConsumer.
     *
     * @param 
     */
    public interface ShortBiConsumer {

        /**
         *
         * @param t
         * @param u
         * @throws E the e
         */
        void accept(short t, short u) throws E;
    }

    /**
     * The Interface IntBiConsumer.
     *
     * @param 
     */
    public interface IntBiConsumer {

        /**
         *
         * @param t
         * @param u
         * @throws E the e
         */
        void accept(int t, int u) throws E;
    }

    /**
     * The Interface LongBiConsumer.
     *
     * @param 
     */
    public interface LongBiConsumer {

        /**
         *
         * @param t
         * @param u
         * @throws E the e
         */
        void accept(long t, long u) throws E;
    }

    /**
     * The Interface FloatBiConsumer.
     *
     * @param 
     */
    public interface FloatBiConsumer {

        /**
         *
         * @param t
         * @param u
         * @throws E the e
         */
        void accept(float t, float u) throws E;
    }

    /**
     * The Interface DoubleBiConsumer.
     *
     * @param 
     */
    public interface DoubleBiConsumer {

        /**
         *
         * @param t
         * @param u
         * @throws E the e
         */
        void accept(double t, double u) throws E;
    }

    /**
     * The Interface BooleanTriPredicate.
     *
     * @param 
     */
    public interface BooleanTriPredicate {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        boolean test(boolean a, boolean b, boolean c) throws E;
    }

    /**
     * The Interface CharTriPredicate.
     *
     * @param 
     */
    public interface CharTriPredicate {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        boolean test(char a, char b, char c) throws E;
    }

    /**
     * The Interface ByteTriPredicate.
     *
     * @param 
     */
    public interface ByteTriPredicate {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        boolean test(byte a, byte b, byte c) throws E;
    }

    /**
     * The Interface ShortTriPredicate.
     *
     * @param 
     */
    public interface ShortTriPredicate {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        boolean test(short a, short b, short c) throws E;
    }

    /**
     * The Interface IntTriPredicate.
     *
     * @param 
     */
    public interface IntTriPredicate {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        boolean test(int a, int b, int c) throws E;
    }

    /**
     * The Interface LongTriPredicate.
     *
     * @param 
     */
    public interface LongTriPredicate {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        boolean test(long a, long b, long c) throws E;
    }

    /**
     * The Interface FloatTriPredicate.
     *
     * @param 
     */
    public interface FloatTriPredicate {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        boolean test(float a, float b, float c) throws E;
    }

    /**
     * The Interface DoubleTriPredicate.
     *
     * @param 
     */
    public interface DoubleTriPredicate {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        boolean test(double a, double b, double c) throws E;
    }

    /**
     * The Interface BooleanTriFunction.
     *
     * @param 
     * @param 
     */
    public interface BooleanTriFunction {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        R apply(boolean a, boolean b, boolean c) throws E;
    }

    /**
     * The Interface CharTriFunction.
     *
     * @param 
     * @param 
     */
    public interface CharTriFunction {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        R apply(char a, char b, char c) throws E;
    }

    /**
     * The Interface ByteTriFunction.
     *
     * @param 
     * @param 
     */
    public interface ByteTriFunction {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        R apply(byte a, byte b, byte c) throws E;
    }

    /**
     * The Interface ShortTriFunction.
     *
     * @param 
     * @param 
     */
    public interface ShortTriFunction {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        R apply(short a, short b, short c) throws E;
    }

    /**
     * The Interface IntTriFunction.
     *
     * @param 
     * @param 
     */
    public interface IntTriFunction {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        R apply(int a, int b, int c) throws E;
    }

    /**
     * The Interface LongTriFunction.
     *
     * @param 
     * @param 
     */
    public interface LongTriFunction {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        R apply(long a, long b, long c) throws E;
    }

    /**
     * The Interface FloatTriFunction.
     *
     * @param 
     * @param 
     */
    public interface FloatTriFunction {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        R apply(float a, float b, float c) throws E;
    }

    /**
     * The Interface DoubleTriFunction.
     *
     * @param 
     * @param 
     */
    public interface DoubleTriFunction {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @return
         * @throws E the e
         */
        R apply(double a, double b, double c) throws E;
    }

    /**
     * The Interface BooleanTriConsumer.
     *
     * @param 
     */
    public interface BooleanTriConsumer {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @throws E the e
         */
        void accept(boolean a, boolean b, boolean c) throws E;
    }

    /**
     * The Interface CharTriConsumer.
     *
     * @param 
     */
    public interface CharTriConsumer {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @throws E the e
         */
        void accept(char a, char b, char c) throws E;
    }

    /**
     * The Interface ByteTriConsumer.
     *
     * @param 
     */
    public interface ByteTriConsumer {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @throws E the e
         */
        void accept(byte a, byte b, byte c) throws E;
    }

    /**
     * The Interface ShortTriConsumer.
     *
     * @param 
     */
    public interface ShortTriConsumer {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @throws E the e
         */
        void accept(short a, short b, short c) throws E;
    }

    /**
     * The Interface IntTriConsumer.
     *
     * @param 
     */
    public interface IntTriConsumer {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @throws E the e
         */
        void accept(int a, int b, int c) throws E;
    }

    /**
     * The Interface LongTriConsumer.
     *
     * @param 
     */
    public interface LongTriConsumer {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @throws E the e
         */
        void accept(long a, long b, long c) throws E;
    }

    /**
     * The Interface FloatTriConsumer.
     *
     * @param 
     */
    public interface FloatTriConsumer {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @throws E the e
         */
        void accept(float a, float b, float c) throws E;
    }

    /**
     * The Interface DoubleTriConsumer.
     *
     * @param 
     */
    public interface DoubleTriConsumer {

        /**
         *
         * @param a
         * @param b
         * @param c
         * @throws E the e
         */
        void accept(double a, double b, double c) throws E;
    }

    /**
     * The Interface ObjBooleanConsumer.
     *
     * @param 
     * @param 
     */
    public interface ObjBooleanConsumer {

        /**
         *
         * @param t
         * @param value
         * @throws E the e
         */
        void accept(T t, boolean value) throws E;
    }

    /**
     * The Interface ObjCharConsumer.
     *
     * @param 
     * @param 
     */
    public interface ObjCharConsumer {

        /**
         *
         * @param t
         * @param value
         * @throws E the e
         */
        void accept(T t, char value) throws E;
    }

    /**
     * The Interface ObjByteConsumer.
     *
     * @param 
     * @param 
     */
    public interface ObjByteConsumer {

        /**
         *
         * @param t
         * @param value
         * @throws E the e
         */
        void accept(T t, byte value) throws E;
    }

    /**
     * The Interface ObjShortConsumer.
     *
     * @param 
     * @param 
     */
    public interface ObjShortConsumer {

        /**
         *
         * @param t
         * @param value
         * @throws E the e
         */
        void accept(T t, short value) throws E;
    }

    /**
     * The Interface ObjIntConsumer.
     *
     * @param 
     * @param 
     */
    public interface ObjIntConsumer {

        /**
         *
         * @param t
         * @param value
         * @throws E the e
         */
        void accept(T t, int value) throws E;
    }

    /**
     * The Interface ObjLongConsumer.
     *
     * @param 
     * @param 
     */
    public interface ObjLongConsumer {

        /**
         *
         * @param t
         * @param value
         * @throws E the e
         */
        void accept(T t, long value) throws E;
    }

    /**
     * The Interface ObjFloatConsumer.
     *
     * @param 
     * @param 
     */
    public interface ObjFloatConsumer {

        /**
         *
         * @param t
         * @param value
         * @throws E the e
         */
        void accept(T t, float value) throws E;
    }

    /**
     * The Interface ObjDoubleConsumer.
     *
     * @param 
     * @param 
     */
    public interface ObjDoubleConsumer {

        /**
         *
         * @param t
         * @param value
         * @throws E the e
         */
        void accept(T t, double value) throws E;
    }

    public interface IntObjConsumer {
        /**
         *
         * @param i
         * @param t
         * @throws E
         */
        void accept(int i, T t) throws E;

        default IntObjConsumer andThen(final IntObjConsumer after) {
            N.checkArgNotNull(after);

            return (i, t) -> {
                accept(i, t);
                after.accept(i, t);
            };
        }
    }

    public interface BiIntObjConsumer {

        /**
         *
         * @param i
         * @param j
         * @param t
         * @throws E
         */
        void accept(int i, int j, T t) throws E;

        default BiIntObjConsumer andThen(final BiIntObjConsumer after) {
            N.checkArgNotNull(after);

            return (i, j, t) -> {
                accept(i, j, t);
                after.accept(i, j, t);
            };
        }
    }

    public static final class EE {
        private EE() {
            // Singleton. Utility class.
        }

        public interface Runnable {

            void run() throws E, E2;
        }

        public interface Callable {

            R call() throws E, E2;
        }

        public interface Supplier {

            T get() throws E, E2;
        }

        public interface Predicate {

            boolean test(T t) throws E, E2;
        }

        public interface BiPredicate {

            boolean test(T t, U u) throws E, E2;
        }

        public interface TriPredicate {

            boolean test(A a, B b, C c) throws E, E2;
        }

        public interface Function {

            R apply(T t) throws E, E2;
        }

        public interface BiFunction {

            R apply(T t, U u) throws E, E2;
        }

        public interface TriFunction {

            R apply(A a, B b, C c) throws E, E2;
        }

        public interface Consumer {

            void accept(T t) throws E, E2;
        }

        public interface BiConsumer {

            void accept(T t, U u) throws E, E2;
        }

        public interface TriConsumer {

            void accept(A a, B b, C c) throws E, E2;
        }
    }

    /**
     * The Class EEE.
     */
    public static final class EEE {

        private EEE() {
            // Singleton. Utility class.
        }

        public interface Runnable {

            void run() throws E, E2, E3;
        }

        public interface Callable {

            R call() throws E, E2, E3;
        }

        public interface Supplier {

            T get() throws E, E2, E3;
        }

        public interface Predicate {

            boolean test(T t) throws E, E2, E3;
        }

        public interface BiPredicate {

            boolean test(T t, U u) throws E, E2, E3;
        }

        public interface TriPredicate {

            boolean test(A a, B b, C c) throws E, E2, E3;
        }

        public interface Function {

            R apply(T t) throws E, E2, E3;
        }

        public interface BiFunction {

            R apply(T t, U u) throws E, E2, E3;
        }

        public interface TriFunction {

            R apply(A a, B b, C c) throws E, E2, E3;
        }

        public interface Consumer {

            void accept(T t) throws E, E2, E3;
        }

        public interface BiConsumer {

            void accept(T t, U u) throws E, E2, E3;
        }

        public interface TriConsumer {

            void accept(A a, B b, C c) throws E, E2, E3;
        }
    }

    public static final class LazyInitializer implements Throwables.Supplier {
        private volatile boolean initialized = false;
        private volatile T value = null;
        private final Supplier supplier;

        LazyInitializer(final Throwables.Supplier supplier) {
            N.checkArgNotNull(supplier, "supplier");

            this.supplier = supplier;
        }

        @Override
        public T get() throws E {
            if (!initialized) {
                synchronized (this) {
                    if (!initialized) {
                        value = supplier.get();

                        initialized = true;
                    }

                }
            }

            return value;
        }

        /**
         *
         * @param 
         * @param supplier
         * @return
         */
        public static  LazyInitializer of(final Throwables.Supplier supplier) {
            N.checkArgNotNull(supplier);

            if (supplier instanceof LazyInitializer) {
                return (LazyInitializer) supplier;
            }

            return new LazyInitializer<>(supplier);
        }
    }
}