com.github.andyshao.util.function.ExceptionableSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Gear Show documentation
Show all versions of Gear Show documentation
Enhance and formating the coding of JDK
The newest version!
package com.github.andyshao.util.function;
import com.github.andyshao.lang.Convert;
import com.github.andyshao.util.stream.RuntimeExceptionFactory;
import java.util.function.Supplier;
/**
*
*
* Title:
* Descript:
* Copyright: Copryright(c) Jun 5, 2019
* Encoding: UNIX UTF-8
*
* @author Andy.Shao
*
* @param return type
* @see Supplier
*/
@FunctionalInterface
public interface ExceptionableSupplier {
/**
* get operation
* @return the value
* @throws Throwable any error
*/
R get() throws Throwable;
/**
* to supplier
* @param f exception factory
* @return {@link Supplier}
* @param data type
*/
static Convert, Supplier> toSupplier(RuntimeExceptionFactory> f) {
return input -> {
return () -> {
try {
return input.get();
} catch (Throwable e) {
throw f.build(e);
}
};
};
}
/**
* to supplier
* @return {@link Supplier}
* @param data type
*/
static Convert, Supplier> toSupplier() {
return toSupplier(RuntimeExceptionFactory.DEFAULT);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy