T - Type of the source of this event.S - The concrete type of the extending class.L - Type of the listener which can handle this event.DefaultDispatchable instead.@Deprecated public abstract class DefaultTargetEvent<T,S extends Event<?,L>,L extends Listener> extends Event<T,L>
EventProvider's dispatch method. As dispatch may be called often for
some kind of events, it is easier to statically provide the method reference
to the listening method. That is what this event class is for.
Due to Java's type system, this kind of events need a third type parameter
SELF which must be set to the class you are implementing. Here is a
sample implementation:
public class UserEvent extends DefaultTargetEvent<UserManager, UserEvent, UserListener> {
public UserEvent(UserManager source) {
super(source, UserListener.class);
}
@Override
public BiConsumer<UserListener, UserEvent> getTarget() {
return UserListener::userAdded;
}
}
As you can see, the middle parameter is set to the implementing class's name
itself to be available as type parameter for the return type of
getTarget(). Thereby, these events are completely compatible with
the EventProvider's dispatch method:
eventProvider.dispatch(event, event.getTarget())
This allows for the creation of a more convenient dispatch overload which only takes the event as parameter and internally delegates to the above shown overload:
eventProvider.dispatch(event)
Event| Constructor and Description |
|---|
DefaultTargetEvent(T source,
Class<L> listenerClass)
Deprecated.
Creates a new event with a given source.
|
| Modifier and Type | Method and Description |
|---|---|
abstract BiConsumer<L,S> |
getTarget()
Deprecated.
|
getListenerClass, getListenerStore, getProperties, getSource, getValue, getValueAs, isHandled, isPrevented, setHandled, setListenerStore, setPrevented, setValue, stopNotifying@Deprecated public abstract BiConsumer<L,S> getTarget()
Copyright © 2014–2015. All rights reserved.