Class ExecutableGenerator<T>

Type Parameters:
T - The type of generated values
All Implemented Interfaces:
Generator, TypedGenerator<T>
Direct Known Subclasses:
ConstructorGenerator, FactoryMethodGenerator

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

    • ExecutableGenerator

      protected ExecutableGenerator(@NotNull @NotNull Class<T> type, @NotNull @NotNull Executable executable, @NotNull @NotNull TargetedGenerator<?>[] paramGenerators)
      Creates a new instance.
      Parameters:
      type - The type of generated values
      executable - The executable to call
      paramGenerators - The generator for the executable parameters
  • 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
    • 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 generated values
      Parameters:
      type - The type of generated values
      method - The factory method to call
      Returns:
      The created generator
    • getExecutable

      @NotNull public @NotNull Executable getExecutable()
      Returns the executable to call.
      Returns:
      The executable to call
    • getParameterGenerators

      @NotNull public @NotNull TargetedGenerator<?>[] getParameterGenerators()
      Returns the generator for the executable parameters.
      Returns:
      The generator for the executable parameters
    • defaultValue

      @NotNull public T defaultValue()
      Returns the default instance of the target type.
      Returns:
      The default instance
    • randomValue

      @NotNull public T randomValue()
      Returns a random instance of the target type.
      Returns:
      A random instance
    • generate

      @NotNull protected abstract T generate(Object[] params)
      Calls the executable to create a new instance of the target type.
      Parameters:
      params - The parameters to use when calling the executable
      Returns:
      The created instance
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AbstractTypedGenerator<T>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class AbstractTypedGenerator<T>