Class EventListenerList.EventListenerIterator<T extends Event>
- java.lang.Object
-
- org.apache.commons.configuration2.event.EventListenerList.EventListenerIterator<T>
-
- 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 specialIterator
implementation used by thegetEventListenerIterator()
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 Summary
Fields Modifier and Type Field Description private java.util.Set<EventType<?>>
acceptedTypes
The set with accepted event types.private EventType<T>
baseEventType
The base event type.private EventListener<? super T>
nextElement
The next element in the iteration.private java.util.Iterator<EventListenerRegistrationData<?>>
underlyingIterator
The underlying iterator.
-
Constructor Summary
Constructors Modifier Constructor Description private
EventListenerIterator(java.util.Iterator<EventListenerRegistrationData<?>> it, EventType<T> base)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private EventListener<? super T>
castListener(EventListenerRegistrationData<?> regData)
Extracts the listener from the given data object and performs a cast to the target type.boolean
hasNext()
private void
initNextElement()
Determines the next element in the iteration.void
invokeNext(Event event)
Obtains the next event listener in this iteration and invokes it with the given event object.private void
invokeNextListenerUnchecked(Event event)
Invokes the next event listener in the iteration without doing a validity check on the event.EventListener<? super T>
next()
void
remove()
This implementation always throws an exception.private void
validateEvent(Event event)
Checks whether the specified event can be passed to an event listener in this iteration.
-
-
-
Field Detail
-
underlyingIterator
private final java.util.Iterator<EventListenerRegistrationData<?>> underlyingIterator
The underlying iterator.
-
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.
-
-
Constructor Detail
-
EventListenerIterator
private EventListenerIterator(java.util.Iterator<EventListenerRegistrationData<?>> it, EventType<T> base)
-
-
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()
-
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()
-
remove
public void remove()
This implementation always throws an exception. Removing elements is not supported.
-
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
-
-