Package org.djutils.event.util
Class EventProducingList<E>
- java.lang.Object
-
- org.djutils.event.EventProducer
-
- org.djutils.event.util.EventProducingList<E>
-
- Type Parameters:
E
- the type of elements in the list
- All Implemented Interfaces:
Serializable
,Iterable<E>
,Collection<E>
,EventListener
,List<E>
,EventListenerInterface
,EventProducerInterface
public class EventProducingList<E> extends EventProducer implements EventListenerInterface, List<E>
The Event producing list provides a list 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 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 class org.djutils.event.EventProducer
eventProducerImpl
-
Fields inherited from interface org.djutils.event.EventProducerInterface
FIRST_POSITION, LAST_POSITION
-
-
Constructor Summary
Constructors Constructor Description EventProducingList(List<E> parent, Serializable sourceId)
constructs a new EventProducingList.EventProducingList(List<E> parent, IdProvider sourceIdProvider)
Constructs a new EventProducingList.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
boolean
add(E o)
boolean
addAll(int index, Collection<? extends E> c)
boolean
addAll(Collection<? extends E> c)
void
clear()
boolean
contains(Object o)
boolean
containsAll(Collection<?> c)
E
get(int index)
Serializable
getSourceId()
Provide the sourceId that will be transmitted with the fired Event.int
indexOf(Object o)
boolean
isEmpty()
EventProducingIterator<E>
iterator()
int
lastIndexOf(Object o)
EventProducingListIterator<E>
listIterator()
EventProducingListIterator<E>
listIterator(int index)
void
notify(EventInterface event)
Notifies the event listener of an event.E
remove(int index)
boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
boolean
retainAll(Collection<?> c)
E
set(int index, E element)
int
size()
List<E>
subList(int fromIndex, int toIndex)
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, 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
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
equals, hashCode, replaceAll, sort, spliterator
-
-
-
-
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
-
EventProducingList
public EventProducingList(List<E> parent, Serializable sourceId)
constructs a new EventProducingList.- Parameters:
parent
- List<E>; the parent list.sourceId
- Serializable; the id by which the EventProducer can be identified by the EventListener
-
EventProducingList
public EventProducingList(List<E> parent, IdProvider sourceIdProvider)
Constructs a new EventProducingList.- Parameters:
parent
- List<E>; 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:
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
public boolean add(E o)
-
addAll
public boolean addAll(Collection<? extends E> c)
-
addAll
public boolean addAll(int index, Collection<? extends E> c)
-
contains
public boolean contains(Object o)
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceList<E>
-
iterator
public EventProducingIterator<E> iterator()
-
listIterator
public EventProducingListIterator<E> listIterator()
- Specified by:
listIterator
in interfaceList<E>
-
listIterator
public EventProducingListIterator<E> listIterator(int index)
- Specified by:
listIterator
in interfaceList<E>
-
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:
notify
in interfaceEventListenerInterface
- Parameters:
event
- EventInterface; the event which is sent to the listener- Throws:
RemoteException
- If a network connection failure occurs.
-
lastIndexOf
public int lastIndexOf(Object o)
- Specified by:
lastIndexOf
in interfaceList<E>
-
remove
public boolean remove(Object o)
-
removeAll
public boolean removeAll(Collection<?> c)
-
retainAll
public boolean retainAll(Collection<?> c)
-
toArray
public Object[] toArray()
-
-