Class EnumGenerator

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

@API(status=STABLE, since="0.1") @Priority(-2000) public class EnumGenerator extends AbstractGenerator
Generator of enumeration types values.

Requires that the enumeration type contain constants.

Since:
0.1
Version:
1.0, 2022-10
Author:
(w) Iker Hernaez
  • Constructor Details

    • EnumGenerator

      public EnumGenerator()
      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.
    • randomEnumValue

      @NotNull public static <T extends Enum<T>> T randomEnumValue(@NotNull @NotNull Class<T> type)
      Returns a random constant of the specified enumeration.
      Type Parameters:
      T - The enumeration type
      Parameters:
      type - The enumeration type
      Returns:
      A random enumeration constant
      Throws:
      IllegalArgumentException - If the enumeration has no constants