Interface Lifecycled<T>

Type Parameters:
T - the value type
All Known Implementing Classes:
ConstantLifecycled, SimpleLifecycled

public interface Lifecycled<T>
Represents an object with a simple valid/invalid lifecycle.

A lifecycled object will start with no value, then trigger Lifecycled.Events.onNewValue(Object, BiConsumer) callbacks when it gets one, and Lifecycled.Events.onInvalidated(Object, BiConsumer) callbacks when it loses it. A full invalidated->new value cycle is called a "reload".

Downstream lifecycled objects can be derived using functional methods, and share some common rules. They will apply the operation sometime before the result is needed, either eagerly or lazily. They will re-do the operation after the upstream Lifecycled is reloaded.

Unless specified, Lifecycled objects are not thread-safe. However, the Lifecycled.Events objects are, and callbacks may be added from any thread.

  • Method Details

    • value

      Optional<T> value()
      Get the value or Optional.empty().
      Returns:
      the value
    • valueOrThrow

      default T valueOrThrow() throws IllegalStateException
      Get the value or throw.
      Returns:
      the value
      Throws:
      IllegalStateException - if there is no value
    • isValid

      default boolean isValid()
      Check for validity, usually without triggering computation.
      Returns:
      if this lifecycled's value() is valid
    • events

      Lifecycled.Events<T> events()
      Get the event manager for this lifecycled object.
      Returns:
      the event manager
    • map

      default <U> Lifecycled<U> map(Function<T,U> mapper)
      Map the value.
      Type Parameters:
      U - the new type
      Parameters:
      mapper - the mapper function
      Returns:
      the downstream lifecycled
    • filter

      default Lifecycled<T> filter(Predicate<T> filterer)
      Filter the value. In other words, create a new lifecycled object where validity is ANDed with the result of calling the filter function.
      Parameters:
      filterer - the filter function
      Returns:
      the downstream lifecycled
    • flatMap

      default <U> Lifecycled<U> flatMap(Function<T,Lifecycled<U>> mapper)