Class LazyReference<T>

java.lang.Object
net.xun.armory.impl.util.LazyReference<T>
Type Parameters:
T - the type of object to be lazily initialized
All Implemented Interfaces:
Supplier<T>

@Internal public class LazyReference<T> extends Object implements Supplier<T>
Internal utility class for lazy initialization of objects.

Note: This class is part of the internal API and is not intended for use by external mods. It may change or be removed without notice in future versions.

This class wraps a Supplier and ensures that the object is created only once, on the first call to get(). Subsequent calls return the same instance. This pattern is useful for deferring expensive object creation until it's actually needed, and for avoiding circular dependencies during initialization.

This is an internal implementation detail of the Armory API. Use the public API classes (ToolSet, ArmorSet) instead of interacting with this class directly.

  • Constructor Details

    • LazyReference

      public LazyReference(String name, Supplier<T> supplier)
      Constructs a new LazyReference with a name and a supplier.
      Parameters:
      name - a descriptive name for the object (used for debugging or logging)
      supplier - the supplier that will provide the object when needed
      Throws:
      NullPointerException - if name or supplier is null
  • Method Details

    • get

      public T get()
      Returns the lazily initialized object.

      If this is the first call, the object is created by calling the supplier. Subsequent calls return the same instance (no additional initialization occurs). This method is thread-safe for the initial creation, but subsequent reads may not be synchronized.

      Specified by:
      get in interface Supplier<T>
      Returns:
      the lazily initialized object
    • getName

      public String getName()
      Gets the name associated with this lazy reference.

      This name is typically used for registration or identification purposes, such as constructing registry IDs for items.

      Returns:
      the name of this lazy reference