Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame] | 1 | package org.apache.felix.dm.lambda.callbacks; |
| 2 | |
| 3 | import java.util.Objects; |
| 4 | |
| 5 | /** |
| 6 | * Represents a java8 method reference to a zero-argument method from a given component implementation class. |
| 7 | * <p> The type of the class on which the callback is invoked on is represented by the T generic parameter. |
| 8 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 9 | */ |
| 10 | @FunctionalInterface |
| 11 | public interface Cb<T> extends SerializableLambda { |
| 12 | /** |
| 13 | * Invokes the callback method on the given component implementation instance. |
| 14 | * @param t the component implementation instance the callback is invoked on. |
| 15 | */ |
| 16 | void accept(T t); |
| 17 | |
| 18 | default Cb<T> andThen(Cb<? super T> after) { |
| 19 | Objects.requireNonNull(after); |
| 20 | return (T t) -> { |
| 21 | accept(t); |
| 22 | after.accept(t); |
| 23 | }; |
| 24 | } |
| 25 | } |