Class FactoryMethodGenerator<T>

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

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

    • FactoryMethodGenerator

      protected FactoryMethodGenerator(@NotNull @NotNull Class<T> type, @NotNull @NotNull Method method, @NotNull @NotNull TargetedGenerator<?>[] paramGenerators)
      Creates a new instance.
      Parameters:
      type - The type of generated values
      method - The factory method to call
      paramGenerators - The parameter generators
  • Method Details

    • of

      public static <T> FactoryMethodGenerator<T> of(@NotNull @NotNull Class<T> type, @NotNull @NotNull Method method)
      Creates a new instance that will call the specified factory method.
      Type Parameters:
      T - The type of the generated instance
      Parameters:
      type - The type of generated values
      method - The factory method to call
      Returns:
      The created generator
    • getExecutable

      public Method 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