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

com.tinkerpop.gremlin.util.function.FunctionUtils Maven / Gradle / Ivy

package com.tinkerpop.gremlin.util.function;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author Stephen Mallette (http://stephen.genoprime.com)
 */
public final class FunctionUtils {
    private FunctionUtils() {
    }

    public static  Function wrapFunction(final ThrowingFunction functionThatThrows) {
        return (a) -> {
            try {
                return functionThatThrows.apply(a);
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        };
    }

    public static  Consumer wrapConsumer(final ThrowingConsumer consumerThatThrows) {
        return (a) -> {
            try {
                consumerThatThrows.accept(a);
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        };
    }

    public static  Supplier wrapSupplier(final ThrowingSupplier supplierThatThrows) {
        return () -> {
            try {
                return supplierThatThrows.get();
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        };
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy