Class ConstructorGenerator<T>

Type Parameters:
T - The type of generated values
All Implemented Interfaces:
Generator, TypedGenerator<T>

@API(status=EXPERIMENTAL, since="0.1") public class ConstructorGenerator<T> extends ExecutableGenerator<T>
Generator that calls a constructor with generated parameters to generate values of the target type.
Since:
0.1
Version:
1.0, 2022-12
Author:
(w) Iker Hernaez
  • Constructor Details

    • ConstructorGenerator

      protected ConstructorGenerator(@NotNull @NotNull Constructor<T> constructor, @NotNull @NotNull TargetedGenerator<?>[] paramGenerators)
      Creates a new instance.
      Parameters:
      constructor - The constructor to call
      paramGenerators - The parameter generators
  • Method Details

    • of

      public static <T> ConstructorGenerator<T> of(@NotNull @NotNull Constructor<T> constructor)
      Creates a new instance that will call the specified constructor.
      Type Parameters:
      T - The type of the generated instance
      Parameters:
      constructor - The constructor to call
      Returns:
      The created generator
    • getExecutable

      public Constructor<T> getExecutable()
      Returns the executable to call.
      Overrides:
      getExecutable in class ExecutableGenerator<T>
      Returns:
      The executable to call
    • generate

      @NotNull protected T generate(Object[] params)
      Calls the executable to create a new instance of the target type.
      Specified by:
      generate in class ExecutableGenerator<T>
      Parameters:
      params - The parameters to use when calling the executable
      Returns:
      The created instance