Class Lazy<T>

java.lang.Object
net.minecraftforge.gradleutils.shared.Lazy<T>
Type Parameters:
T - The type of result
All Implemented Interfaces:
Callable<T>, Supplier<T>
Direct Known Subclasses:
Lazy.Actionable

public sealed class Lazy<T> extends Object implements Supplier<T>, Callable<T> permits Lazy.Actionable<T>
This is a simple implementation of a Lazy value, primarily aimed for use in Java code.
See Also:
API Note:
This lazy implementation uses Groovy's closures instead of typical suppliers or callables, as the closure API allows chaining via Closure.compose(Closure) and Closure.andThen(Closure). They can still be created using callables.
  • Field Details

    • closure

      protected final Closure<T> closure
      The closure that will provide the value for this lazy.
    • value

      @Nullable protected T value
      The value of this lazy, will be null if it has not yet been computed with get().
  • Method Details

    • simple

      public static <T> Lazy<T> simple(Callable<T> callable)
      Creates a simple lazy of the given callable.
      Type Parameters:
      T - The return type of the callable
      Parameters:
      callable - The callable to use
      Returns:
      The lazy value
    • simple

      public static <T> Lazy<T> simple(Closure<T> closure)
      Creates a simple lazy of the given closure.
      Type Parameters:
      T - The return type of the closure
      Parameters:
      closure - The callable to use
      Returns:
      The lazy value
    • actionable

      public static <T> Lazy.Actionable<T> actionable(Callable<T> callable)
      Creates an actionable lazy of the given callable.
      Type Parameters:
      T - The return type of the callable
      Parameters:
      callable - The callable to use
      Returns:
      The lazy value
    • actionable

      public static <T> Lazy.Actionable<T> actionable(Closure<T> closure)
      Creates an actionable lazy of the given closure.
      Type Parameters:
      T - The return type of the closure
      Parameters:
      closure - The callable to use
      Returns:
      The lazy value
    • isPresent

      public boolean isPresent()

      Checks if this lazy value is present. It is not a requirement that the value has to be resolved.

      For simple lazies, it is simply a check if the value has been resolved. See Lazy.Actionable.isPresent() for actionable lazies.

      Returns:
      If this lazy is present
    • ifPresent

      public final void ifPresent(Action<? super T> action)
      Runs the given action on this lazy value if it is present.
      Parameters:
      action - The action to run
      See Also:
    • get

      public T get()
      Gets (and resolves if absent) this lazy value.
      Specified by:
      get in interface Supplier<T>
      Returns:
      The value
    • call

      public T call()
      Specified by:
      call in interface Callable<T>