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 | import org.apache.felix.dm.Component; |
| 6 | |
| 7 | /** |
| 8 | * Represents a swap callback(Service, Service, Component) on an Object instance. |
| 9 | * |
| 10 | * <p> The type of the service passed in argument to the callback is defined by the "S" generic parameter. |
| 11 | * |
| 12 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 13 | */ |
| 14 | @FunctionalInterface |
| 15 | public interface InstanceCbServiceServiceComponent<S> extends SerializableLambda { |
| 16 | /** |
| 17 | * Handles the given arguments. |
| 18 | * @param c the component |
| 19 | * @param old the old service |
| 20 | * @param replace the new service |
| 21 | */ |
| 22 | void accept(S old, S replace, Component c); |
| 23 | |
| 24 | default InstanceCbServiceServiceComponent<S> andThen(InstanceCbServiceServiceComponent<S> after) { |
| 25 | Objects.requireNonNull(after); |
| 26 | return (S old, S replace, Component c) -> { |
| 27 | accept(old, replace, c); |
| 28 | after.accept(old, replace, c); |
| 29 | }; |
| 30 | } |
| 31 | } |