Class Initializer<T>

java.lang.Object
net.regsirius06.engine.API.Initializer<T>
Type Parameters:
T - the type of object that this initializer will create
All Implemented Interfaces:
Serializable, Loadable
Direct Known Subclasses:
LabyrinthPanelInit

public abstract class Initializer<T> extends Object implements Loadable, Serializable
Abstract class that provides a way to initialize objects of type T.

Initializer is used to supply a method of creating an object of type T. The class does not load anything directly, but custom initializers can be loaded via InitializersPluginLoader if needed. Subclasses should implement the getName() and create(Object...) methods to define the specific initialization logic.

In the application, an initializer is typically used in the context of creating objects like LabyrinthPanel, as shown in LabyrinthPanelInit, where the initializer provides a way to create specific instances of complex objects.

The generic type T represents the type of object that will be created, and the getType() method returns the class of that type.

See Also:
  • Constructor Details

    • Initializer

      public Initializer()
      Constructs a new Initializer and extracts the generic type T from the subclass.

      This constructor uses reflection to determine the actual type of T based on the subclass that extends Initializer. If the type parameter T is not specified, a runtime exception will be thrown.

      Throws:
      RuntimeException - if the type parameter T is not specified in the subclass
  • Method Details

    • getType

      public Class<T> getType()
      Returns the Class object of the type T.

      This method provides access to the type of object that will be created by this initializer.

      Returns:
      the Class object representing the type of T
    • getName

      public abstract String getName()
      Returns the name of the initializer.

      This method must be implemented by subclasses to provide a human-readable name for the initializer. This name is typically used to identify the initializer in the application.

      Returns:
      the name of the initializer
    • create

      public abstract T create(Object... objects) throws IllegalArgumentException
      Creates an instance of type T using the provided arguments.

      This method must be implemented by subclasses to define how an object of type T is created. The objects parameter can contain any necessary data required for object creation, and the method should return the created instance. It may throw exceptions if the arguments are invalid or if the creation fails for any reason.

      Parameters:
      objects - the arguments needed to create an object of type T
      Returns:
      an instance of type T
      Throws:
      IllegalArgumentException - if the arguments are invalid or insufficient for object creation