Module org.arakhne.afc.core.util
Package org.arakhne.afc.util
Class ListenerCollection<L extends EventListener>
- java.lang.Object
-
- org.arakhne.afc.util.ListenerCollection<L>
-
- Type Parameters:
L
- is the type of listeners.
public class ListenerCollection<L extends EventListener> extends Object
A collection of listeners.This collection is thread-safe.
This class is inspirated by
EventListenerList
.- Version:
- 17.0 2020-01-04 14:41:38
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- util
-
-
Constructor Summary
Constructors Constructor Description ListenerCollection()
Construct a listener collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends EventListener>
voidadd(Class<T> type, T listener)
Adds the listener as a listener of the specified type.void
clear()
Clear this collection.int
getListenerCount(Class<?> type)
Returns the total number of listeners of the supplied type for this listener list.Object[]
getListenerList()
Passes back the event listener list as an array of ListenerType-listener pairs.<T extends EventListener>
T[]getListeners(Class<T> type)
Return an array of all the listeners of the given type.boolean
isEmpty()
Replies if this collection is empty.<T extends EventListener>
voidremove(Class<T> type, T listener)
Removes the listener as a listener of the specified type.int
size()
Returns the total number of listeners for this listener list.String
toString()
-
-
-
Field Detail
-
listeners
protected transient Object[] listeners
Listeners.
-
-
Method Detail
-
isEmpty
@Pure public boolean isEmpty()
Replies if this collection is empty.- Returns:
true
if this collection does not contains any listener, otherwisefalse
-
clear
public void clear()
Clear this collection.
-
getListenerList
@Pure public Object[] getListenerList()
Passes back the event listener list as an array of ListenerType-listener pairs. Note that for performance reasons, this implementation passes back the actual data structure in which the listener data is stored internally! This method is guaranteed to pass back a non-null array, so that no null-checking is required in fire methods. A zero-length array of Object should be returned if there are currently no listeners.WARNING!!! Absolutely NO modification of the data contained in this array should be made -- if any such manipulation is necessary, it should be done on a copy of the array returned rather than the array itself.
- Returns:
- the listeners.
-
getListeners
@Pure public <T extends EventListener> T[] getListeners(Class<T> type)
Return an array of all the listeners of the given type.- Type Parameters:
T
- is the type of expected listeners.- Parameters:
type
- is the type of expected listeners.- Returns:
- all of the listeners of the specified type.
- Throws:
ClassCastException
- if the supplied class is not assignable to EventListener
-
size
@Pure public int size()
Returns the total number of listeners for this listener list.- Returns:
- the total number of listeners for this listener list.
-
getListenerCount
@Pure public int getListenerCount(Class<?> type)
Returns the total number of listeners of the supplied type for this listener list.- Parameters:
type
- the type of the listeners.- Returns:
- the total number of listeners of the supplied type for this listener list.
-
add
public <T extends EventListener> void add(Class<T> type, T listener)
Adds the listener as a listener of the specified type.- Type Parameters:
T
- the type of the listener to be added- Parameters:
type
- the type of the listener to be addedlistener
- the listener to be added
-
remove
public <T extends EventListener> void remove(Class<T> type, T listener)
Removes the listener as a listener of the specified type.- Type Parameters:
T
- the type of the listener to be removed- Parameters:
type
- the type of the listener to be removedlistener
- the listener to be removed
-
-