Class LazyValue<T>

java.lang.Object
org.moddingx.libx.util.lazy.LazyValue<T>

public class LazyValue<T> extends Object
A lazy value that is resolved when it is first used.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LazyValue(Supplier<? extends T> supplier)
    Creates a new lazy value.
  • Method Summary

    Modifier and Type
    Method
    Description
    asDefault(net.minecraftforge.common.util.LazyOptional<T> optional)
    Gets a lazy value that will have the value of the lazy optional if present.
    get()
    Gets the value.
    <U> LazyValue<U>
    map(Function<T,U> mapper)
    Gets a new lazy value that will hold the value of this lazy value applied to the mapper function.
    static <T> LazyValue<T>
    wrap(net.minecraft.util.LazyLoadedValue<T> value)
    Wraps a LazyLoadedValue to a lazy value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LazyValue

      public LazyValue(@Nonnull Supplier<? extends T> supplier)
      Creates a new lazy value. the supplier will be called once when the value is first retrieved.
  • Method Details

    • wrap

      public static <T> LazyValue<T> wrap(net.minecraft.util.LazyLoadedValue<T> value)
      Wraps a LazyLoadedValue to a lazy value.
    • get

      public T get()
      Gets the value. If not yet resolved, resolves the lazy value.
    • asDefault

      public LazyValue<T> asDefault(net.minecraftforge.common.util.LazyOptional<T> optional)
      Gets a lazy value that will have the value of the lazy optional if present. If not it will have the value of this lazy value.
    • map

      public <U> LazyValue<U> map(Function<T,U> mapper)
      Gets a new lazy value that will hold the value of this lazy value applied to the mapper function. The mapper function will also get called lazy.