Interface Event<T>

Type Parameters:
T - the type of data propagated with this event
All Superinterfaces:
Consumer<T>, EventObserver<T>, Runnable

public interface Event<T> extends Runnable, Consumer<T>, EventObserver<T>
An event class. Listeners are notified in the order they were added.
 Event<Boolean> event = Event.event();

 EventObserver<Boolean> observer = event.observer();

 observer.addListener(this::doSomething);
 observer.addConsumer(this::onBoolean);

 event.accept(true);
 
A factory for Event instances.
  • Method Details

    • run

      void run()
      Triggers this event.
      Specified by:
      run in interface Runnable
    • accept

      void accept(T data)
      Triggers this event.
      Specified by:
      accept in interface Consumer<T>
      Parameters:
      data - data associated with the event
    • observer

      EventObserver<T> observer()
      Returns:
      an observer notified each time this event occurs
    • event

      static <T> Event<T> event()
      Creates a new Event.
      Type Parameters:
      T - the type of data propagated to listeners on event occurrence
      Returns:
      a new Event