blob: 15bde585957c6e07d1db1be1a7600fbd0467c9e4 [file] [log] [blame]
Pierre De Ropfaca2892016-01-31 23:27:05 +00001package org.apache.felix.dm.lambda.callbacks;
2
3import java.util.Objects;
4
5import org.apache.felix.dm.Component;
6
7/**
Pierre De Rop11527502016-02-18 21:07:16 +00008 * 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 Ropfaca2892016-01-31 23:27:05 +000011 *
12 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
13 */
14@FunctionalInterface
Pierre De Rop11527502016-02-18 21:07:16 +000015public interface CbComponent<T> extends SerializableLambda {
Pierre De Ropfaca2892016-01-31 23:27:05 +000016 /**
Pierre De Rop11527502016-02-18 21:07:16 +000017 * Handles the given arguments.
18 * @param instance the Component implementation class instance on which the callback is invoked on.
Pierre De Ropfaca2892016-01-31 23:27:05 +000019 * @param component the callback parameter
20 */
Pierre De Rop11527502016-02-18 21:07:16 +000021 void accept(T instance, Component bundle);
Pierre De Ropfaca2892016-01-31 23:27:05 +000022
Pierre De Rop11527502016-02-18 21:07:16 +000023 default CbComponent<T> andThen(CbComponent<? super T> after) {
Pierre De Ropfaca2892016-01-31 23:27:05 +000024 Objects.requireNonNull(after);
Pierre De Rop11527502016-02-18 21:07:16 +000025 return (T instance, Component component) -> {
26 accept(instance, component);
27 after.accept(instance, component);
Pierre De Ropfaca2892016-01-31 23:27:05 +000028 };
29 }
30}