View Javadoc
1   /*-
2    * #%L
3    * io.earcam.unexceptional
4    * %%
5    * Copyright (C) 2016 - 2017 earcam
6    * %%
7    * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT)
8    * 
9    * You <b>must</b> choose to accept, in full - any individual or combination of 
10   * the following licenses:
11   * <ul>
12   * 	<li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li>
13   * 	<li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li>
14   * 	<li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li>
15   * 	<li><a href="https://opensource.org/licenses/MIT">MIT</a></li>
16   * </ul>
17   * #L%
18   */
19  package io.earcam.unexceptional;
20  
21  import java.util.Objects;
22  
23  /**
24   * A checked parallel of {@link java.util.function.BiConsumer}
25   * 
26   * @param <T> first argument type
27   * @param <U> second argument type
28   * @param <E> the type of Throwable declared
29   * 
30   * @since 0.2.0
31   * 
32   * @see java.util.function.BiConsumer
33   */
34  @FunctionalInterface
35  public interface CheckedBiConsumer<T, U, E extends Throwable> {
36  
37  	/**
38  	 * See {@link java.util.function.BiConsumer#accept(Object, Object)}
39  	 * 
40  	 * @param t first argument
41  	 * @param u second argument
42  	 * @throws Throwable a possible checked exception
43  	 */
44  	public abstract void accept(T t, U u) throws E;
45  
46  
47  	/**
48  	 * See {@link java.util.function.BiConsumer#andThen(java.util.function.BiConsumer)}
49  	 * 
50  	 * @param after the bi-consumer to accept sequentially <i>after</i> {@code this}
51  	 * @return the composite {@link CheckedBiConsumer}
52  	 * @throws NullPointerException if {@code after} is {@code null}
53  	 */
54  	@SuppressWarnings("squid:S1905") // SonarQube false positives
55  	public default CheckedBiConsumer<T, U, E> andThen(CheckedBiConsumer<? super T, ? super U, ? extends E> after)
56  	{
57  		Objects.requireNonNull(after);
58  
59  		return (CheckedBiConsumer<T, U, E> & java.io.Serializable) (l, r) -> {
60  			accept(l, r);
61  			after.accept(l, r);
62  		};
63  	}
64  }