Class EventListenerList.EventListenerIterator<T extends Event>

  • Type Parameters:
    T - the event type
    All Implemented Interfaces:
    java.util.Iterator<EventListener<? super T>>
    Enclosing class:
    EventListenerList

    public static final class EventListenerList.EventListenerIterator<T extends Event>
    extends java.lang.Object
    implements java.util.Iterator<EventListener<? super T>>
    A special Iterator implementation used by the getEventListenerIterator() method. This iterator returns only listeners compatible with a specified event type. It has a convenience method for invoking the current listener in the iteration with an event.
    • Field Detail

      • baseEventType

        private final EventType<T extends Event> baseEventType
        The base event type.
      • acceptedTypes

        private final java.util.Set<EventType<?>> acceptedTypes
        The set with accepted event types.
      • nextElement

        private EventListener<? super T extends Event> nextElement
        The next element in the iteration.
    • Method Detail

      • castListener

        private EventListener<? super T> castListener​(EventListenerRegistrationData<?> regData)
        Extracts the listener from the given data object and performs a cast to the target type. This is safe because it has been checked before that the type is compatible.
        Parameters:
        regData - the data object
        Returns:
        the extracted listener
      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<T extends Event>
      • initNextElement

        private void initNextElement()
        Determines the next element in the iteration.
      • invokeNext

        public void invokeNext​(Event event)
        Obtains the next event listener in this iteration and invokes it with the given event object.
        Parameters:
        event - the event object
        Throws:
        java.util.NoSuchElementException - if iteration is at its end
      • invokeNextListenerUnchecked

        private void invokeNextListenerUnchecked​(Event event)
        Invokes the next event listener in the iteration without doing a validity check on the event. This method is called internally to avoid duplicate event checks.
        Parameters:
        event - the event object
      • next

        public EventListener<? super T> next()
        Specified by:
        next in interface java.util.Iterator<T extends Event>
      • remove

        public void remove()
        This implementation always throws an exception. Removing elements is not supported.
        Specified by:
        remove in interface java.util.Iterator<T extends Event>
      • validateEvent

        private void validateEvent​(Event event)
        Checks whether the specified event can be passed to an event listener in this iteration. This check is done via the hierarchy of event types.
        Parameters:
        event - the event object
        Throws:
        java.lang.IllegalArgumentException - if the event is invalid