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.addDataListener(this::onBoolean);

 event.accept(true);
 
A factory class 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
    • listener

      static <T> Runnable listener(Consumer<T> listener)
      Creates a Runnable causing the listeners Consumer.accept(Object) to be called with a null argument on each occurrence.
      Type Parameters:
      T - the value type
      Parameters:
      listener - the data listener
      Returns:
      a Runnable causing the given Consumer to be called with null data on each occurrence
    • dataListener

      static <T> Consumer<T> dataListener(Runnable listener)
      Creates a Consumer causing the listeners Runnable.run() to be called on each occurrence. Note that any event data will get discarded along the way.
      Type Parameters:
      T - the type of data propagated to listeners on event occurrence
      Parameters:
      listener - the listener
      Returns:
      a Consumer causing the given Runnable to be called on each occurrence