Class AbstractParameterizableGenerator<P extends GenerationParameters>

java.lang.Object
dev.orne.test.rnd.AbstractGenerator
dev.orne.test.rnd.params.AbstractParameterizableGenerator<P>
Type Parameters:
P - The parameters type
All Implemented Interfaces:
Generator, ParameterizableGenerator
Direct Known Subclasses:
AbstractTypedParameterizableGenerator

@API(status=EXPERIMENTAL, since="0.1") public abstract class AbstractParameterizableGenerator<P extends GenerationParameters> extends AbstractGenerator implements ParameterizableGenerator
Abstract implementation of ParameterizableGenerator.
Since:
0.1
Version:
1.0, 2022-11
Author:
(w) Iker Hernaez
  • Constructor Details

    • AbstractParameterizableGenerator

      protected AbstractParameterizableGenerator(@NotNull @NotNull Class<P> paramsType)
      Creates a new instance.
      Parameters:
      paramsType - The type of parameters
    • AbstractParameterizableGenerator

      protected AbstractParameterizableGenerator()
      Crates a new instance.
  • Method Details

    • getParametersType

      @NotNull public @NotNull Class<P> getParametersType()
      Returns the type of generation parameters.
      Returns:
      The type of generation parameters
    • getExtractor

      @NotNull public @NotNull ParametersExtractor<P> getExtractor()
      Returns the generation parameters extractor.
      Returns:
      The generation parameters extractor
    • defaultValue

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

      @NotNull public <T> T defaultValue(@NotNull @NotNull Class<T> type, @NotNull @NotNull Object... sources)
      Returns the default value for the specified type and parameter sources.
      Specified by:
      defaultValue in interface ParameterizableGenerator
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      sources - The parameter sources to extract the parameters from
      Returns:
      The default value for the specified type.
    • defaultValue

      @NotNull public abstract <T> T defaultValue(@NotNull @NotNull Class<T> type, @NotNull P parameters)
      Returns the default value for the specified type and parameters.
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      parameters - The generation parameters
      Returns:
      The default value for the specified type.
      Throws:
      IllegalArgumentException - If the specified type is not supported.
    • nullableDefaultValue

      public <T> T nullableDefaultValue(@NotNull @NotNull Class<T> type)
      Returns the default value for the specified type allowing null values.

      This method should return null except for native types.

      Specified by:
      nullableDefaultValue in interface Generator
      Overrides:
      nullableDefaultValue in class AbstractGenerator
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      Returns:
      The nullable default value for the specified type.
    • nullableDefaultValue

      public <T> T nullableDefaultValue(@NotNull @NotNull Class<T> type, @NotNull @NotNull Object... sources)
      Returns the default value for the specified type and parameter sources allowing null values.

      This method should return null except for native types when no NotNull constraint is present.

      Specified by:
      nullableDefaultValue in interface ParameterizableGenerator
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      sources - The parameter sources to extract the parameters from
      Returns:
      The nullable default value for the specified type.
    • nullableDefaultValue

      public <T> T nullableDefaultValue(@NotNull @NotNull Class<T> type, @NotNull P parameters)
      Returns the default value for the specified type and parameters allowing null values.

      This method should return null except for native types when no NotNull constraint is present.

      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      parameters - The generation parameters
      Returns:
      The nullable default value for the specified type.
      Throws:
      IllegalArgumentException - If the specified type is not supported.
    • randomValue

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

      @NotNull public <T> T randomValue(@NotNull @NotNull Class<T> type, @NotNull @NotNull Object... sources)
      Returns a random value of the specified type and parameter sources.
      Specified by:
      randomValue in interface ParameterizableGenerator
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      sources - The parameter sources to extract the parameters from
      Returns:
      A random value for the specified type.
    • randomValue

      @NotNull public abstract <T> T randomValue(@NotNull @NotNull Class<T> type, @NotNull P parameters)
      Returns a random value of the specified type and parameters.
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      parameters - The generation parameters
      Returns:
      A random value for the specified type.
      Throws:
      IllegalArgumentException - If the specified type is not supported.
    • 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:
    • nullableRandomValue

      public <T> T nullableRandomValue(@NotNull @NotNull Class<T> type, @NotNull @NotNull Object... sources)
      Returns a random value of the specified type and parameter sources.

      The returned value has a probability of be null except for native types when no NotNull constraint is present. If not null behaves as randomValue().

      Specified by:
      nullableRandomValue in interface ParameterizableGenerator
      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      sources - The parameter sources to extract the parameters from
      Returns:
      A random nullable value for the specified type.
      See Also:
    • nullableRandomValue

      public <T> T nullableRandomValue(@NotNull @NotNull Class<T> type, @NotNull P parameters)
      Returns a random value of the specified type and parameters.

      The returned value has a probability of be null except for native types when no NotNull constraint is present. If not null behaves as randomValue().

      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      parameters - The generation parameters
      Returns:
      A random nullable value for the specified type.
      Throws:
      IllegalArgumentException - If the specified type is not supported.
      See Also:
    • createEmptyParams

      @NotNull public P createEmptyParams()
      Creates a new empty instance of generation parameters.
      Returns:
      A new empty instance of generation parameters.
    • createParams

      @NotNull public P createParams(@NotNull @NotNull Object... sources)
      Creates a new instance of generation parameters with the values extracted from the specified sources.
      Parameters:
      sources - The sources to extract the parameters values from
      Returns:
      A new instance of generation parameters.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AbstractGenerator
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class AbstractGenerator