Class ListenerCollection<L extends EventListener>

  • 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
    • Field Detail

      • listeners

        protected transient Object[] listeners
        Listeners.
    • Constructor Detail

      • ListenerCollection

        public ListenerCollection()
        Construct a listener collection.
    • Method Detail

      • isEmpty

        @Pure
        public boolean isEmpty()
        Replies if this collection is empty.
        Returns:
        true if this collection does not contains any listener, otherwise false
      • 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 added
        listener - 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 removed
        listener - the listener to be removed