Package org.djutils.event.util
Class EventProducingSet<E>
java.lang.Object
org.djutils.event.EventProducer
org.djutils.event.util.EventProducingSet<E>
- Type Parameters:
E
- the type of elements in the set
- All Implemented Interfaces:
Serializable
,Iterable<E>
,Collection<E>
,EventListener
,Set<E>
,EventListenerInterface
,EventProducerInterface
public class EventProducingSet<E> extends EventProducer implements EventListenerInterface, Set<E>
The Event producing set 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 on
map.iterator.remove()
. A listener
must subscribe to the iterator individually.
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_ADDED_EVENT
OBJECT_ADDED_EVENT is fired on new entries.static EventType
OBJECT_CHANGED_EVENT
OBJECT_CHANGED_EVENT is fired on change of one or more entries.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 EventProducingSet(Set<E> parent, Serializable sourceId)
Constructs a new EventProducingSet.EventProducingSet(Set<E> parent, IdProvider sourceIdProvider)
Constructs a new EventProducingSet. -
Method Summary
Modifier and Type Method Description boolean
add(E o)
boolean
addAll(Collection<? extends E> c)
void
clear()
boolean
contains(Object o)
boolean
containsAll(Collection<?> c)
Serializable
getSourceId()
Provide the sourceId that will be transmitted with the fired Event.boolean
isEmpty()
EventProducingIterator<E>
iterator()
void
notify(EventInterface event)
Notifies the event listener of an event.boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
boolean
retainAll(Collection<?> c)
int
size()
Object[]
toArray()
<T> T[]
toArray(T[] a)
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_ADDED_EVENT
OBJECT_ADDED_EVENT is fired on new entries. -
OBJECT_REMOVED_EVENT
OBJECT_REMOVED_EVENT is fired on removal of entries. -
OBJECT_CHANGED_EVENT
OBJECT_CHANGED_EVENT is fired on change of one or more entries.
-
-
Constructor Details
-
EventProducingSet
Constructs a new EventProducingSet.- Parameters:
parent
- Set<E>; the parent set.sourceId
- Serializable; the id by which the EventProducer can be identified by the EventListener
-
EventProducingSet
Constructs a new EventProducingSet.- Parameters:
parent
- Set<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
-
size
public int size() -
isEmpty
public boolean isEmpty() -
clear
public void clear() -
add
-
addAll
-
contains
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
-
iterator
-
notify
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:
notify
in interfaceEventListenerInterface
- Parameters:
event
- EventInterface; the event which is sent to the listener- Throws:
RemoteException
- If a network connection failure occurs.
-
remove
-
removeAll
-
retainAll
-
toArray
-
toArray
public <T> T[] toArray(T[] a)
-