Package com.helger.base.callback
Class CallbackList<CALLBACKTYPE extends ICallback>
java.lang.Object
com.helger.base.callback.CallbackList<CALLBACKTYPE>
- Type Parameters:
CALLBACKTYPE- The callback type.
- All Implemented Interfaces:
ICallbackList<CALLBACKTYPE>,ICloneable<CallbackList<CALLBACKTYPE>>,IHasSize,Iterable<CALLBACKTYPE>
@ThreadSafe
public class CallbackList<CALLBACKTYPE extends ICallback>
extends Object
implements ICallbackList<CALLBACKTYPE>, ICloneable<CallbackList<CALLBACKTYPE>>
This class manages a list of callbacks. In reality it is a Set of callbacks.
- Author:
- Philip Helger
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor with an empty callback list.CallbackList(@Nullable CallbackList<CALLBACKTYPE> aOther) Copy constructor. -
Method Summary
Modifier and TypeMethodDescription@NonNull EChangeadd(@NonNull CALLBACKTYPE aCallback) Add a callback.final @NonNull EChangeaddAll(@NonNull CALLBACKTYPE... aCallbacks) Add an array of elements to this collection.voidforEach(@NonNull Consumer<? super CALLBACKTYPE> aConsumer) @NonNull EContinueforEachBreakable(@NonNull Function<? super CALLBACKTYPE, EContinue> aFunction) Iterate all callbacks and invoke the provided function.@NonNull List<CALLBACKTYPE> @Nullable CALLBACKTYPEgetCallbackAtIndex(int nIndex) Get the callback at the specified index.@NonNull CallbackList<CALLBACKTYPE> getClone()booleanisEmpty()@NonNull Iterator<CALLBACKTYPE> iterator()@NonNull EChangeRemove all callbacks@NonNull EChangeremoveObject(@Nullable CALLBACKTYPE aCallback) Remove the specified callback@NonNull EChangeset(@NonNull CALLBACKTYPE aCallback) Clear all elements and add only the passed value.@NonNull EChangeset(@NonNull CallbackList<CALLBACKTYPE> rhs) Clear all elements and add all provided values.intsize()toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.base.iface.IHasSize
isNotEmptyMethods inherited from interface java.lang.Iterable
spliterator
-
Constructor Details
-
CallbackList
public CallbackList()Default constructor with an empty callback list. -
CallbackList
Copy constructor.- Parameters:
aOther- The callback list to copy from. May benull.
-
-
Method Details
-
set
Clear all elements and add all provided values. If no value is provided,the collection is empty afterwards.- Parameters:
rhs- the callback list to set. May not benull.- Returns:
EChange
-
set
Clear all elements and add only the passed value.- Parameters:
aCallback- The callback to be used. May not benull.- Returns:
EChange
-
add
Add a callback.- Parameters:
aCallback- May not benull.- Returns:
EChange
-
addAll
Add an array of elements to this collection.- Parameters:
aCallbacks- The elements to be added. May be null.- Returns:
EChange
-
removeObject
Remove the specified callback- Parameters:
aCallback- May benull.- Returns:
EChange
-
removeAll
Remove all callbacks- Returns:
EChange
-
getAllCallbacks
- Specified by:
getAllCallbacksin interfaceICallbackList<CALLBACKTYPE extends ICallback>- Returns:
- A mutable copy of all registered callbacks. Never
null.
-
getCallbackAtIndex
Get the callback at the specified index.- Specified by:
getCallbackAtIndexin interfaceICallbackList<CALLBACKTYPE extends ICallback>- Parameters:
nIndex- The index to retrieve. Must be ≥ 0.- Returns:
nullif the index is out of bounds.
-
size
@Nonnegative public int size() -
isEmpty
public boolean isEmpty() -
getClone
- Specified by:
getClonein interfaceICloneable<CALLBACKTYPE extends ICallback>- Returns:
- A clone of this callback list. Never
null.
-
iterator
- Specified by:
iteratorin interfaceIterable<CALLBACKTYPE extends ICallback>
-
forEach
- Specified by:
forEachin interfaceIterable<CALLBACKTYPE extends ICallback>
-
forEachBreakable
public @NonNull EContinue forEachBreakable(@NonNull Function<? super CALLBACKTYPE, EContinue> aFunction) Iterate all callbacks and invoke the provided function. Iteration can be stopped by returningEContinue.BREAK.- Parameters:
aFunction- The function to be invoked on each callback. May not benull.- Returns:
EContinue.BREAKif iteration was stopped,EContinue.CONTINUEotherwise.
-
toString
-