Class WireProvider<F>

java.lang.Object
dev.wyck.factory.WireProvider<F>
Type Parameters:
F - the type of the factory
Direct Known Subclasses:
ConstructWireProvider, OptionalWireProvider

@NullMarked @AsOf("2.2.0") @Internal public sealed class WireProvider<F> extends Object permits OptionalWireProvider<F>, ConstructWireProvider<F>
A provider for lazily loading factory instances based on the active Minecraft version.
Since:
2.0.0
  • Field Details

    • factory

      protected volatile @Nullable F factory
  • Constructor Details

    • WireProvider

      protected WireProvider(String classNameTemplate)
  • Method Details

    • create

      @AsOf("2.0.0") public static <F> WireProvider<F> create(String template)
      Creates a new WireProvider instance.
      Type Parameters:
      F - the type of the factory
      Parameters:
      template - the class name template to use for loading the factory
      Returns:
      a new WireProvider instance
      Since:
      2.0.0
    • empty

      @AsOf("2.4.1") public static <F> OptionalWireProvider<F> empty()
      Creates a WireProvider that does not reflectively instantiate anything.
      Type Parameters:
      F - the type of the factory
      Returns:
      a WireProvider that is empty
      Since:
      2.4.1
    • construct

      @AsOf("2.4.1") public static <F> ConstructWireProvider<F> construct(String template)
      Creates a WireProvider that uses the given template to construct the factory.
      Type Parameters:
      F - the type of the factory
      Parameters:
      template - the class name template to use for loading the factory
      Returns:
      a WireProvider that constructs the factory using the given template
      Since:
      2.4.1
    • isRegistered

      @AsOf("2.0.0") public boolean isRegistered()
      Checks if the factory has been registered.
      Returns:
      true if the factory has been registered, false otherwise
    • get

      @AsOf("2.0.0") public F get()
      Gets the factory instance.
      Returns:
      the factory instance
    • getNew

      @AsOf("2.2.0") public F getNew()
      Forces a new factory instance, bypassing the cached singleton. The resolved class and constructor are cached internally, so only the instantiation cost is paid per call.
      Returns:
      a fresh factory instance
    • resolveClass

      @AsOf("2.3.0") protected Class<? extends F> resolveClass()
      Resolves the backing factory class from classNameTemplate, applying whichever version operator the template uses.
      Returns:
      the resolved factory class
    • setProvider

      public void setProvider(Class<?> caller, F factory)