Package org.goplanit.utils.event
Class EventProducerImpl
- java.lang.Object
-
- org.goplanit.utils.event.EventProducerImpl
-
- Direct Known Subclasses:
DemandsModifier
,DirectedGraphModifierImpl
,GraphModifierImpl
,PlanitComponentFactory
,RoutedServicesLayerModifierImpl
,ZoningModifierImpl
public abstract class EventProducerImpl extends Object
The EventProducer is the base class able to produce events. It provides protected methods to register listeners and remove listeners as well as ways to fire a generic event. Event producing classes should either extend this class to provide more user friendly public methods with the correct signatures that enforce the appropriate event and listener combinations suitable for that particular class while internally making use of this implementations functionality.- Author:
- markr
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<EventType,Map<EventListenerPriority,List<EventListener>>>
listeners
The collection of interested listeners by event and priority
-
Constructor Summary
Constructors Modifier Constructor Description protected
EventProducerImpl()
Constructs a new EventProducer and checks for duplicate values in event types.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addListener(EventListener listener)
add a listener for one or more event types that are presumably triggered by this producer absed on its known supported types.protected void
addListener(EventListener listener, EventListenerPriority priority)
Add a listener for one or more event types (collected from listener's known supported types) that are presumably triggered by this producerprotected void
addListener(EventListener listener, EventListenerPriority priority, EventType... eventTypes)
Add a listener for one or more event types that are presumably triggered by this producerprotected void
addListener(EventListener listener, EventType... eventTypes)
Add a listener for one or more event types that are presumably triggered by this producer, with the default priority (low)protected void
fireEvent(Event event)
Transmit an event to all interested listeners.protected abstract void
fireEvent(EventListener eventListener, Event event)
Let derived class deal with the handling of the listener, where based on the derived event implementation the listener's concrete class can be determined which in turn allows for calling the right event callback method which is unknown at this base level since this event mechanism does not force a particular notification method signature on its listener interfaceSet<EventType>
getEventTypesWithListeners()
Determine the event types have one or more listeners registeredboolean
hasListener(EventType eventType)
Verify if one or more listeners are registered for given event typeboolean
hasListeners()
Verify if any listeners are availableint
numberOfListeners(EventType eventType)
Determine the number of listeners for a given event typevoid
removeAllListeners()
Remove all the listeners from this producerprotected boolean
removeListener(EventListener listener)
Remove listener from all event types it is registered onprotected boolean
removeListener(EventListener listener, EventType eventType)
Remove a listener for a given event type
-
-
-
Field Detail
-
listeners
protected Map<EventType,Map<EventListenerPriority,List<EventListener>>> listeners
The collection of interested listeners by event and priority
-
-
Method Detail
-
addListener
protected final void addListener(EventListener listener, EventListenerPriority priority)
Add a listener for one or more event types (collected from listener's known supported types) that are presumably triggered by this producer- Parameters:
listener
- to registerpriority
- to apply for the combination of listener and event type(s)
-
addListener
protected final void addListener(EventListener listener, EventListenerPriority priority, EventType... eventTypes)
Add a listener for one or more event types that are presumably triggered by this producer- Parameters:
listener
- to registerpriority
- to apply for the combination of listener and event type(s)eventTypes
- to register the listener for
-
addListener
protected final void addListener(EventListener listener, EventType... eventTypes)
Add a listener for one or more event types that are presumably triggered by this producer, with the default priority (low)- Parameters:
listener
- to registereventTypes
- to register the listener for
-
addListener
protected final void addListener(EventListener listener)
add a listener for one or more event types that are presumably triggered by this producer absed on its known supported types. If no known types are not available the listener will not be added and a warning is issued- Parameters:
listener
- to add
-
removeListener
protected final boolean removeListener(EventListener listener, EventType eventType)
Remove a listener for a given event type- Parameters:
listener
- to removeeventType
- to remove it for- Returns:
- true when succeeded, false otherwise
-
removeListener
protected final boolean removeListener(EventListener listener)
Remove listener from all event types it is registered on- Parameters:
listener
- to remove- Returns:
- true when removed from one or more event types it was registered for, false otherwise
-
fireEvent
protected abstract void fireEvent(EventListener eventListener, Event event)
Let derived class deal with the handling of the listener, where based on the derived event implementation the listener's concrete class can be determined which in turn allows for calling the right event callback method which is unknown at this base level since this event mechanism does not force a particular notification method signature on its listener interface- Parameters:
eventListener
- to notify for the eventevent
- to process for the listener
-
fireEvent
protected void fireEvent(Event event)
Transmit an event to all interested listeners.- Parameters:
event
- the event fired
-
removeAllListeners
public void removeAllListeners()
Remove all the listeners from this producer
-
hasListeners
public boolean hasListeners()
Verify if any listeners are available- Returns:
- true when present, false otherwise
-
hasListener
public boolean hasListener(EventType eventType)
Verify if one or more listeners are registered for given event type- Parameters:
eventType
- to verify- Returns:
- true when present, false otherwise
-
numberOfListeners
public int numberOfListeners(EventType eventType)
Determine the number of listeners for a given event type- Parameters:
eventType
- to check- Returns:
- number of listeners
-
-