![JAR search and dependency download from the Maven repository](/logo.png)
com.github.andyshao.util.function.ExceptionableConsumer 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.Objects;
import java.util.function.Consumer;
/**
*
*
* Title:
* Descript:
* Copyright: Copryright(c) May 27, 2019
* Encoding: UNIX UTF-8
*
* @author Andy.Shao
*
* @param argument type
*/
@FunctionalInterface
public interface ExceptionableConsumer {
/**
* accept operation
* @param t input
* @throws Throwable any error
*/
void accept(T t) throws Throwable;
/**
* to consumer
* @param f exception convert factory
* @return {@link Convert}
* @param data type
*/
static Convert, Consumer> toConsumer(RuntimeExceptionFactory> f) {
return input -> {
return t -> {
try {
input.accept(t);
} catch (Throwable e) {
throw f.build(e);
}
};
};
}
/**
* to consumer
* @return {@link Convert}
* @param data type
*/
static Convert, Consumer> toConsumer() {
return toConsumer(RuntimeExceptionFactory.DEFAULT);
}
/**
* and then
* @param after after {@link ExceptionableConsumer}
* @return new {@link ExceptionableConsumer}
*/
default ExceptionableConsumer andThen(ExceptionableConsumer super T> after) {
Objects.requireNonNull(after);
return it -> {
this.accept(it);
after.accept(it);
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy