com.github.ulisesbocchio.spring.boot.security.saml.util.FunctionalUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-boot-security-saml Show documentation
Show all versions of spring-boot-security-saml Show documentation
Eases Integration between Spring Boot and spring-security-saml through properties and adapters
The 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;
}
}