Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 1 | package org.apache.felix.dm.lambda.callbacks; |
| 2 | |
| 3 | import java.util.Objects; |
| 4 | |
| 5 | import org.apache.felix.dm.Component; |
| 6 | |
| 7 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 8 | * Represents a callback(Component) that is invoked on a Component implementation class. |
| 9 | * The type of the component implementation class on which the callback is invoked on is represented by the T generic parameter. |
| 10 | * The component callback accepts in argument a Component parameter. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 11 | * |
| 12 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 13 | */ |
| 14 | @FunctionalInterface |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 15 | public interface CbComponent<T> extends SerializableLambda { |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 16 | /** |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 17 | * Handles the given arguments. |
| 18 | * @param instance the Component implementation class instance on which the callback is invoked on. |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 19 | * @param component the callback parameter |
| 20 | */ |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 21 | void accept(T instance, Component bundle); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 22 | |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 23 | default CbComponent<T> andThen(CbComponent<? super T> after) { |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 24 | Objects.requireNonNull(after); |
Pierre De Rop | 1152750 | 2016-02-18 21:07:16 +0000 | [diff] [blame^] | 25 | return (T instance, Component component) -> { |
| 26 | accept(instance, component); |
| 27 | after.accept(instance, component); |
Pierre De Rop | faca289 | 2016-01-31 23:27:05 +0000 | [diff] [blame] | 28 | }; |
| 29 | } |
| 30 | } |