- java.lang.Object
- 
- aeonics.util.Callback<V,T>
 
- 
- Type Parameters:
- V- the type of data that triggered this callback
- T- the type of the target class of this callback
 - All Implemented Interfaces:
- java.lang.Iterable<Functions.BiConsumer<V,T>>
 
 public class Callback<V,T> extends java.lang.Object implements java.lang.Iterable<Functions.BiConsumer<V,T>> This class can be used to set a callback method.The callback will call every registered handlers with the trigger value and a reference to the target object instance. This way, you do not have to keep a reference to the outer scope from a lambda expression. // DO THIS : use the provided target MyClass instance = new MyClass(); instance.callback.then((value, target) -> { target.something(); }); // AVOID THIS : reference the outer scope MyClass instance = new MyClass(); instance.callback.then((value, target) -> { instance.something(); });Consider using one of the once(BiConsumer)variants for handlers that should execute only once.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classCallback.Once<U,S>This class specified that a callback handler should only run once and then be removed from the list of handlers.
 - 
Constructor SummaryConstructors Constructor Description Callback(Functions.Supplier<T> target)Creates a new callback for the specified target supplier.Callback(T target)Creates a new callback for the specified target
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Removes all handlers from this callback.java.util.Iterator<Functions.BiConsumer<V,T>>iterator()Provides an unmodifiable iterator over registered handlers for this callback.static <U,S>
 Callback.Once<U,S>once(Functions.BiConsumer<U,S> handler)Returns a handler that will only run once.static <U,S>
 Callback.Once<U,S>once(Functions.Runnable handler)Returns a handler that will only run once.voidremove(Functions.BiConsumer<V,T> handler)Removes the specified handler from this callback.voidthen(Functions.BiConsumer<V,T> handler)Adds a handler for this callback.voidtrigger()Triggers the handlers with a null valuevoidtrigger(V value)Triggers the handlers with the specified value.
 
- 
- 
- 
Constructor Detail- 
Callbackpublic Callback(T target) Creates a new callback for the specified target- Parameters:
- target- the target of this callback
 
 - 
Callbackpublic Callback(Functions.Supplier<T> target) Creates a new callback for the specified target supplier. Upon trigger, the target value is fetched once before returning and cached during the handler propagation.- Parameters:
- target- the getter for the target of this callback
 
 
- 
 - 
Method Detail- 
oncepublic static <U,S> Callback.Once<U,S> once(Functions.BiConsumer<U,S> handler) Returns a handler that will only run once.- Type Parameters:
- U- the type of data that triggered this callback
- S- the type of the target class of this callback
- Parameters:
- handler- the handler that should only run once. You may provide a- Functions.BiConsumerthat will be given the callback target as second argument.
- Returns:
- a handler that will only run once
 
 - 
oncepublic static <U,S> Callback.Once<U,S> once(Functions.Runnable handler) Returns a handler that will only run once.- Type Parameters:
- U- the type of data that triggered this callback
- S- the type of the target class of this callback
- Parameters:
- handler- the handler that should only run once
- Returns:
- a handler that will only run once
 
 - 
thenpublic void then(Functions.BiConsumer<V,T> handler) Adds a handler for this callback.Consider Callback.Onceif the handler should only run once.- Parameters:
- handler- the handler
 
 - 
removepublic void remove(Functions.BiConsumer<V,T> handler) Removes the specified handler from this callback.- Parameters:
- handler- the handler
 
 - 
clearpublic void clear() Removes all handlers from this callback.
 - 
triggerpublic void trigger() Triggers the handlers with a null value
 - 
triggerpublic void trigger(V value) Triggers the handlers with the specified value. All handlers are executed synchronously and sequentially- Parameters:
- value- the value
 
 - 
iteratorpublic java.util.Iterator<Functions.BiConsumer<V,T>> iterator() Provides an unmodifiable iterator over registered handlers for this callback. Note that the iterator is not thread safe in case handlers are added or removed during iteration.- Specified by:
- iteratorin interface- java.lang.Iterable<V>
 
 
- 
 
-