Class Lazy<T>

java.lang.Object
org.stianloader.smatterdi.Lazy<T>

public class Lazy<T> extends Object
  • Constructor Details

    • Lazy

      public Lazy(@NotNull Supplier<T> supplier)
    • Lazy

      public Lazy(@NotNull T value)
  • Method Details

    • get

      @NotNull @Contract(pure=false) public T get()
      Obtains the value of the lazy.

      If the value hasn't yet been computed, the value will get computed and all registered configurators are called on the computed value.

      A lazy will not be computed twice if the supplier or a configurator throws a Throwable. Instead, the exception will be rethrown in a packaged form.

      Returns:
      The value of the lazy
    • getIfPresent

      @NotNull @Contract(pure=true) public Optional<T> getIfPresent()
      If the value of the lazy object was already calculated, this method returns a non-empty options. Otherwise (as get() was not called yet), it will return an empty optional.
      Returns:
      The current value of the optional
    • configure

      @NotNull @Contract(mutates="this", pure=false, value="null -> fail; !null -> this") public Lazy<T> configure(@NotNull Consumer<T> action)
    • isDone

      public boolean isDone()