Package org.djutils.event.util
Class EventProducingCollection<T>
- java.lang.Object
 - 
- org.djutils.event.EventProducer
 - 
- org.djutils.event.util.EventProducingCollection<T>
 
 
 
- 
- Type Parameters:
 T- The type of the event producing Collection.
- All Implemented Interfaces:
 Serializable,Iterable<T>,Collection<T>,EventListener,EventListenerInterface,EventProducerInterface
public class EventProducingCollection<T> extends EventProducer implements EventListenerInterface, Collection<T>
The Event producing collection provides a set to which one can subscribe interest in entry changes. This class does not keep track of changes which take place indirectly. One is for example not notified onmap.iterator.remove(). A listener must subscribe to the iterator individually.Copyright (c) 2002-2021 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 EventTypeOBJECT_ADDED_EVENTOBJECT_ADDED_EVENT is fired on new entries.static EventTypeOBJECT_CHANGED_EVENTOBJECT_CHANGED_EVENT is fired on change of one or more entries.static EventTypeOBJECT_REMOVED_EVENTOBJECT_REMOVED_EVENT is fired on removal of entries.- 
Fields inherited from class org.djutils.event.EventProducer
eventProducerImpl 
- 
Fields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION 
 - 
 
- 
Constructor Summary
Constructors Constructor Description EventProducingCollection(Collection<T> parent, Serializable sourceId)constructs a new EventProducingCollectiont.EventProducingCollection(Collection<T> parent, IdProvider sourceIdProvider)Constructs a new EventProducingCollection. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(T o)booleanaddAll(Collection<? extends T> c)voidclear()booleancontains(Object o)booleancontainsAll(Collection<?> c)SerializablegetSourceId()Provide the sourceId that will be transmitted with the fired Event.booleanisEmpty()EventProducingIterator<T>iterator()voidnotify(EventInterface event)Notifies the event listener of an event.booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)intsize()Object[]toArray()<E> E[]toArray(E[] a)- 
Methods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener 
- 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
- 
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray 
 - 
 
 - 
 
- 
- 
Field Detail
- 
OBJECT_ADDED_EVENT
public static final EventType OBJECT_ADDED_EVENT
OBJECT_ADDED_EVENT is fired on new entries. 
- 
OBJECT_REMOVED_EVENT
public static final EventType OBJECT_REMOVED_EVENT
OBJECT_REMOVED_EVENT is fired on removal of entries. 
- 
OBJECT_CHANGED_EVENT
public static final EventType OBJECT_CHANGED_EVENT
OBJECT_CHANGED_EVENT is fired on change of one or more entries. 
 - 
 
- 
Constructor Detail
- 
EventProducingCollection
public EventProducingCollection(Collection<T> parent, Serializable sourceId)
constructs a new EventProducingCollectiont.- Parameters:
 parent- Collection<T>; the parent collection.sourceId- Serializable; the id by which the EventProducer can be identified by the EventListener
 
- 
EventProducingCollection
public EventProducingCollection(Collection<T> parent, IdProvider sourceIdProvider)
Constructs a new EventProducingCollection.- Parameters:
 parent- Collection<T>; the parent set.sourceIdProvider- IdProvider; the function that produces the id by which the EventProducer can be identified by the EventListener
 
 - 
 
- 
Method Detail
- 
getSourceId
public Serializable getSourceId()
Provide the sourceId that will be transmitted with the fired Event.- Specified by:
 getSourceIdin interfaceEventProducerInterface- Specified by:
 getSourceIdin classEventProducer- Returns:
 - Serializable; the sourceId that will be transmitted with the fired Event
 
 
- 
size
public int size()
- Specified by:
 sizein interfaceCollection<T>
 
- 
isEmpty
public boolean isEmpty()
- Specified by:
 isEmptyin interfaceCollection<T>
 
- 
clear
public void clear()
- Specified by:
 clearin interfaceCollection<T>
 
- 
add
public boolean add(T o)
- Specified by:
 addin interfaceCollection<T>
 
- 
addAll
public boolean addAll(Collection<? extends T> c)
- Specified by:
 addAllin interfaceCollection<T>
 
- 
contains
public boolean contains(Object o)
- Specified by:
 containsin interfaceCollection<T>
 
- 
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
 containsAllin interfaceCollection<T>
 
- 
iterator
public EventProducingIterator<T> iterator()
 
- 
notify
public void notify(EventInterface event) throws RemoteException
Notifies the event listener of an event. This operation forms the callback method of the asynchronous communication protocol expressed in the event package.- Specified by:
 notifyin interfaceEventListenerInterface- Parameters:
 event- EventInterface; the event which is sent to the listener- Throws:
 RemoteException- If a network connection failure occurs.
 
- 
remove
public boolean remove(Object o)
- Specified by:
 removein interfaceCollection<T>
 
- 
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
 removeAllin interfaceCollection<T>
 
- 
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
 retainAllin interfaceCollection<T>
 
- 
toArray
public Object[] toArray()
- Specified by:
 toArrayin interfaceCollection<T>
 
- 
toArray
public <E> E[] toArray(E[] a)
- Specified by:
 toArrayin interfaceCollection<T>
 
 - 
 
 -