Class ArrayGenerator

java.lang.Object
dev.orne.test.rnd.AbstractGenerator
dev.orne.test.rnd.generators.ArrayGenerator
All Implemented Interfaces:
Generator

@API(status=STABLE, since="0.1") @Priority(-2000) public class ArrayGenerator extends AbstractGenerator
Generator of array values. Requires supported component type generation in Generators.
Since:
0.1
Version:
1.0, 2022-11
Author:
(w) Iker Hernaez
  • Field Details

    • MIN_SIZE

      public static final int MIN_SIZE
      The minimum generated array size.
      See Also:
    • MAX_SIZE

      public static final int MAX_SIZE
      The maximum generated array size.
      See Also:
  • Constructor Details

    • ArrayGenerator

      public ArrayGenerator()
      Creates a new instance.
  • Method Details

    • supports

      public boolean supports(@NotNull @NotNull Class<?> type)
      Checks if values of the specified type can be generated by this instance.
      Parameters:
      type - The type to check.
      Returns:
      If values of the specified type can be generated.
    • defaultValue

      @NotNull public <T> T defaultValue(@NotNull @NotNull Class<T> type)
      Returns the default value for the specified type.
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      Returns:
      The default value for the specified type.
    • randomValue

      @NotNull public <T> T randomValue(@NotNull @NotNull Class<T> type)
      Returns a random value of the specified type.
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      Returns:
      A random value for the specified type.
    • randomArray

      @NotNull protected @NotNull Object randomArray(@NotNull @NotNull Class<?> componentType, @NotNull @NotNull Generator generator)
      Returns a random sized array of the specified component type.
      Parameters:
      componentType - The requested component type.
      generator - The generator to use to generate the array values.
      Returns:
      A random array for the specified component type.
      Throws:
      GenerationException - If an error occurs generating the value
    • nullableRandomValue

      public <T> T nullableRandomValue(@NotNull @NotNull Class<T> type)
      Returns a random value of the specified type allowing null values.

      The returned value has a probability of be null except for native types. If not null behaves as randomValue().

      Specified by:
      nullableRandomValue in interface Generator
      Overrides:
      nullableRandomValue in class AbstractGenerator
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      Returns:
      A random nullable value for the specified type.
      See Also:
    • randomNullablesArray

      protected Object randomNullablesArray(@NotNull @NotNull Class<?> componentType, @NotNull @NotNull Generator generator)
      Returns a random sized array of the specified component type allowing null component values.
      Parameters:
      componentType - The requested component type.
      generator - The generator to use for component values.
      Returns:
      A random array of the specified component type.
      Throws:
      GenerationException - If an error occurs generating the value