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

com.github.andyshao.util.function.ExceptionableConsumer Maven / Gradle / Ivy

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 after) { Objects.requireNonNull(after); return it -> { this.accept(it); after.accept(it); }; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy