Package org.djutils.event.util
Class EventProducingMap<K,V>
- java.lang.Object
-
- org.djutils.event.EventProducer
-
- org.djutils.event.util.EventProducingMap<K,V>
-
- Type Parameters:
K
- the key typeV
- the value type
- All Implemented Interfaces:
Serializable
,Map<K,V>
,EventProducerInterface
public class EventProducingMap<K,V> extends EventProducer implements Map<K,V>
The Event producing map provides a map 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, key set, etc. 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 EventProducingMap(Map<K,V> parent, Serializable sourceId)
constructs a new EventProducingMap.EventProducingMap(Map<K,V> parent, IdProvider sourceIdProvider)
Constructs a new EventProducingMap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<K,V>>
entrySet()
V
get(Object key)
Serializable
getSourceId()
Provide the sourceId that will be transmitted with the fired Event.boolean
isEmpty()
Set<K>
keySet()
V
put(K key, V value)
void
putAll(Map<? extends K,? extends V> map)
V
remove(Object key)
int
size()
Collection<V>
values()
-
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.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
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
-
EventProducingMap
public EventProducingMap(Map<K,V> parent, Serializable sourceId)
constructs a new EventProducingMap.- Parameters:
parent
- Map<K,V>; the embedded map.sourceId
- Serializable; the id by which the EventProducer can be identified by the EventListener
-
EventProducingMap
public EventProducingMap(Map<K,V> parent, IdProvider sourceIdProvider)
Constructs a new EventProducingMap.- Parameters:
parent
- Map<K, V>; the parent map.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
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<K,V>
-
-