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

com.github.ulisesbocchio.spring.boot.security.saml.util.FunctionalUtils Maven / Gradle / Ivy

Go to download

Eases Integration between Spring Boot and spring-security-saml through properties and adapters

There is a newer version: 1.17
Show newest version
package com.github.ulisesbocchio.spring.boot.security.saml.util;

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

/**
 * Utilities to overcome functional limitations.
 *
 * @author Ulises Bocchio
 */
public class FunctionalUtils {
    public static  Consumer unchecked(CheckedConsumer consumer) {
        return t -> {
            try {
                consumer.accept(t);
            } catch (Throwable e) {
                RuntimeException r;
                if (e instanceof RuntimeException) {
                    r = (RuntimeException) e;
                } else {
                    r = new RuntimeException(e);
                }
                throw r;
            }
        };
    }

    public static  Function uncheckedFunction(CheckedFunction function) {
        return t -> {
            try {
                return function.apply(t);
            } catch (Throwable e) {
                RuntimeException r;
                if (e instanceof RuntimeException) {
                    r = (RuntimeException) e;
                } else {
                    r = new RuntimeException(e);
                }
                throw r;
            }
        };
    }

    @FunctionalInterface
    public interface CheckedConsumer {
        void accept(T t) throws E;
    }

    @FunctionalInterface
    public interface CheckedFunction {
        R apply(T t) throws E;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy