Package com.helger.commons.callback
Class CallbackList<CALLBACKTYPE extends ICallback>
- java.lang.Object
-
- com.helger.commons.callback.CallbackList<CALLBACKTYPE>
-
- Type Parameters:
CALLBACKTYPE- The callback type.
- All Implemented Interfaces:
ICallbackList<CALLBACKTYPE>,ICommonsIterable<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
Constructors Constructor Description CallbackList()CallbackList(CallbackList<CALLBACKTYPE> aOther)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EChangeadd(CALLBACKTYPE aCallback)Add a callback.EChangeaddAll(CALLBACKTYPE... aCallbacks)Add an array of elements to this collection.voidforEach(Consumer<? super CALLBACKTYPE> aConsumer)EContinueforEachBreakable(Function<? super CALLBACKTYPE,EContinue> aFunction)A special version ofIterable.forEach(Consumer)that can break iteration if a certain requirement is fulfilled.ICommonsList<CALLBACKTYPE>getAllCallbacks()CALLBACKTYPEgetCallbackAtIndex(int nIndex)Get the callback at the specified index.CallbackList<CALLBACKTYPE>getClone()booleanisEmpty()Iterator<CALLBACKTYPE>iterator()EChangeremoveAll()Remove all callbacksEChangeremoveObject(CALLBACKTYPE aCallback)Remove the specified callbackEChangeset(CALLBACKTYPE aCallback)Clear all elements and add only the passed value.EChangeset(CallbackList<CALLBACKTYPE> rhs)Clear all elements and add all provided values.intsize()StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.collection.impl.ICommonsIterable
containsAny, containsNone, containsOnly, findAll, findAllInstanceOf, findAllMapped, findAllMapped, findAllMapped, findFirst, findFirst, findFirstIndex, findFirstMapped, findFirstMapped, findLastIndex, forEachByIndex, forEachThrowing, getCount, getCount
-
Methods inherited from interface com.helger.commons.lang.IHasSize
isNotEmpty
-
Methods inherited from interface java.lang.Iterable
spliterator
-
-
-
-
Constructor Detail
-
CallbackList
public CallbackList()
-
CallbackList
public CallbackList(@Nullable CallbackList<CALLBACKTYPE> aOther)
-
-
Method Detail
-
set
@Nonnull public EChange set(@Nonnull CallbackList<CALLBACKTYPE> rhs)
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
@Nonnull public EChange set(@Nonnull CALLBACKTYPE aCallback)
Clear all elements and add only the passed value.- Parameters:
aCallback- The callback to be used. May not benull.- Returns:
EChange
-
add
@Nonnull public EChange add(@Nonnull CALLBACKTYPE aCallback)
Add a callback.- Parameters:
aCallback- May not benull.- Returns:
EChange
-
addAll
@Nonnull @SafeVarargs public final EChange addAll(@Nonnull CALLBACKTYPE... aCallbacks)
Add an array of elements to this collection.- Parameters:
aCallbacks- The elements to be added. May be null.- Returns:
EChange
-
removeObject
@Nonnull public EChange removeObject(@Nullable CALLBACKTYPE aCallback)
Remove the specified callback- Parameters:
aCallback- May benull.- Returns:
EChange
-
getAllCallbacks
@Nonnull @ReturnsMutableCopy public ICommonsList<CALLBACKTYPE> getAllCallbacks()
- Specified by:
getAllCallbacksin interfaceICallbackList<CALLBACKTYPE extends ICallback>- Returns:
- A list of all callbacks. Never
nulland only containing non-nullelements.
-
getCallbackAtIndex
@Nullable public CALLBACKTYPE getCallbackAtIndex(@Nonnegative int nIndex)
Description copied from interface:ICallbackListGet the callback at the specified index.- Specified by:
getCallbackAtIndexin interfaceICallbackList<CALLBACKTYPE extends ICallback>- Parameters:
nIndex- The index to be retrieved. Should be ≥ 0.- Returns:
nullif the provided index is invalid.
-
size
@Nonnegative public int size()
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceIHasSize- Returns:
trueif no items are present,falseif at least a single item is present.- See Also:
IHasSize.size(),IHasSize.isNotEmpty()
-
getClone
@Nonnull public CallbackList<CALLBACKTYPE> getClone()
- Specified by:
getClonein interfaceICloneable<CALLBACKTYPE extends ICallback>- Returns:
- A 100% deep-copy of the implementing class.
-
iterator
@Nonnull public Iterator<CALLBACKTYPE> iterator()
- Specified by:
iteratorin interfaceIterable<CALLBACKTYPE extends ICallback>
-
forEach
public void forEach(@Nonnull Consumer<? super CALLBACKTYPE> aConsumer)
- Specified by:
forEachin interfaceIterable<CALLBACKTYPE extends ICallback>
-
forEachBreakable
@Nonnull public EContinue forEachBreakable(@Nonnull Function<? super CALLBACKTYPE,EContinue> aFunction)
Description copied from interface:ICommonsIterableA special version ofIterable.forEach(Consumer)that can break iteration if a certain requirement is fulfilled.- Specified by:
forEachBreakablein interfaceICommonsIterable<CALLBACKTYPE extends ICallback>- Parameters:
aFunction- The consumer to be invoked. May not benull.- Returns:
EContinue.BREAKif iteration was stopped,EContinue.CONTINUEotherwise.
-
-