58 lines
1.2 KiB
Java
58 lines
1.2 KiB
Java
package envoy.event;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import dev.kske.eventbus.IEvent;
|
|
|
|
/**
|
|
* This class serves as a convenience base class for all events. It implements the {@link IEvent}
|
|
* interface and provides a generic value. For events without a value there also is
|
|
* {@link envoy.event.Event.Valueless}.
|
|
*
|
|
* @author Kai S. K. Engelbart
|
|
* @param <T> the type of the Event
|
|
* @since Envoy v0.2-alpha
|
|
*/
|
|
public abstract class Event<T> implements IEvent, Serializable {
|
|
|
|
protected final T value;
|
|
|
|
private static final long serialVersionUID = 0L;
|
|
|
|
protected Event(T value) {
|
|
this.value = value;
|
|
}
|
|
|
|
/**
|
|
* @return the data associated with this event
|
|
*/
|
|
public T get() {
|
|
return value;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return String.format("%s[value=%s]", this.getClass().getSimpleName(), value);
|
|
}
|
|
|
|
/**
|
|
* Serves as a super class for events that do not carry a value.
|
|
*
|
|
* @author Kai S. K. Engelbart
|
|
* @since Envoy Common v0.2-alpha
|
|
*/
|
|
public static abstract class Valueless extends Event<Void> {
|
|
|
|
private static final long serialVersionUID = 0L;
|
|
|
|
protected Valueless() {
|
|
super(null);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return this.getClass().getSimpleName();
|
|
}
|
|
}
|
|
}
|