Package com.jgcomptech.tools.events
Class EventTarget<T extends Event>
- java.lang.Object
-
- com.jgcomptech.tools.events.EventTarget<T>
-
- Type Parameters:
T
- the event type to use for the target
- Direct Known Subclasses:
Permission
,PermissionManager
,SessionManager
public class EventTarget<T extends Event> extends java.lang.Object
Allows object event handler registration and forwards received events to the appropriate registered event handlers.- Since:
- 1.4.0
-
-
Constructor Summary
Constructors Constructor Description EventTarget()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEventHandler(EventType<? extends Event> eventType, EventHandler<T> eventHandler)
Sets the specified singleton handler.boolean
equals(java.lang.Object o)
void
fire(Event event, EventType<? extends Event> eventType)
Fires the handle method in all registered EventHandlers.EventHandler<T>
getEventHandler(EventType<? extends T> eventType)
Returns the singleton handler assigned to the specified Event Type.int
hashCode()
void
removeEventHandler(EventType<? extends T> eventType)
Removes the singleton handler assigned to the specified Event Type.java.lang.String
toString()
-
-
-
Method Detail
-
addEventHandler
public final void addEventHandler(EventType<? extends Event> eventType, EventHandler<T> eventHandler)
Sets the specified singleton handler. There can only be one such handler specified at a time.- Parameters:
eventType
- the event type to associate with the given eventHandlereventHandler
- the handler to register, or null to unregister
-
removeEventHandler
public final void removeEventHandler(EventType<? extends T> eventType)
Removes the singleton handler assigned to the specified Event Type.- Parameters:
eventType
- the event type to associate with the given eventHandler
-
getEventHandler
public final EventHandler<T> getEventHandler(EventType<? extends T> eventType)
Returns the singleton handler assigned to the specified Event Type.- Parameters:
eventType
- the event type- Returns:
- the singleton handler assigned to the specified Event Type
-
fire
public final void fire(Event event, EventType<? extends Event> eventType)
Fires the handle method in all registered EventHandlers.- Parameters:
event
- the eventeventType
- the event type
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-