Package org.djutils.event.util
Class EventProducingIterator<T>
java.lang.Object
org.djutils.event.EventProducer
org.djutils.event.util.EventProducingIterator<T>
- Type Parameters:
T
- the type of elements to iterate on
- All Implemented Interfaces:
Serializable
,Iterator<T>
,EventProducerInterface
- Direct Known Subclasses:
EventProducingListIterator
public class EventProducingIterator<T> extends EventProducer implements Iterator<T>
The EventProducingIterator provides an iterator embedding the Iterator, which fires an event when an object has been removed.
Note that one does not have to subscribe specifically to the events of the EventProducingIterator, as the EventProducing
collection subscribes to the EventProducingIterator's remove events and fires these again to its subscribers.
Copyright (c) 2002-2020 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html. This class was originally part of the DSOL project, see https://simulation.tudelft.nl/dsol/manual.
- Author:
- Peter Jacobs , Alexander Verbraeck
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description static EventType
OBJECT_REMOVED_EVENT
OBJECT_REMOVED_EVENT is fired on removal of entries.Fields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION
-
Constructor Summary
Constructors Constructor Description EventProducingIterator(Iterator<T> parent, Serializable sourceId)
constructs a new EventProducingIterator, embedding the parent Iterator.EventProducingIterator(Iterator<T> parent, IdProvider sourceIdProvider)
Constructs a new EventProducingIterator, embedding the parent iterator. -
Method Summary
Modifier and Type Method Description protected Iterator<T>
getParent()
Return the embedded iterator.Serializable
getSourceId()
Provide the sourceId that will be transmitted with the fired Event.boolean
hasNext()
T
next()
void
remove()
Methods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
Field Details
-
OBJECT_REMOVED_EVENT
OBJECT_REMOVED_EVENT is fired on removal of entries.
-
-
Constructor Details
-
EventProducingIterator
constructs a new EventProducingIterator, embedding the parent Iterator.- Parameters:
parent
- Iterator<T>; parent.sourceId
- Serializable; the id by which the EventProducer can be identified by the EventListener
-
EventProducingIterator
Constructs a new EventProducingIterator, embedding the parent iterator.- Parameters:
parent
- Iterator<T>; the parent set.sourceIdProvider
- IdProvider; the function that produces the id by which the EventProducer can be identified by the EventListener
-
-
Method Details
-
getSourceId
Provide the sourceId that will be transmitted with the fired Event.- Specified by:
getSourceId
in interfaceEventProducerInterface
- Specified by:
getSourceId
in classEventProducer
- Returns:
- Serializable; the sourceId that will be transmitted with the fired Event
-
hasNext
public boolean hasNext() -
next
-
remove
public void remove() -
getParent
Return the embedded iterator.- Returns:
- parent Iterator<T>; the embedded iterator
-