Class OnceUntil<T>

java.lang.Object
microsim.caching.OnceUntil<T>
All Implemented Interfaces:
Supplier<T>

public class OnceUntil<T> extends Object implements Supplier<T>

Cache the result of a Supplier so that it is only called only once until the condition becomes true.

This requires the wrapped Supplier to return a non-null object. This is lazy in the sense that the wrapped Supplier is only called when the value is requested (either for the first time or when the simulation time has changed).

  • Constructor Details

    • OnceUntil

      public OnceUntil(Supplier<? extends T> supplier, Supplier<Boolean> condition)
      Build a cache wrapping the given Supplier, using the provided condition to know when the inner value should be updated.
  • Method Details

    • timeChanges

      public static <T> OnceUntil<T> timeChanges(Supplier<? extends T> supplier, SimulationEngine engine)

      Build a cache that updates once per simulation tick.

      This is provided for convenience as this is a common caching condition.

    • get

      public T get()
      Get the value.
      Specified by:
      get in interface Supplier<T>
      Throws:
      NullPointerException - if the wrapped Supplier returns null.