Class AbstractTargetedGenerator<T>

java.lang.Object
dev.orne.test.rnd.params.AbstractTargetedGenerator<T>
Type Parameters:
T - The type of generated values
All Implemented Interfaces:
TargetedGenerator<T>
Direct Known Subclasses:
ConstructorParameterTypeGenerator, MethodParameterTypeGenerator, MethodReturnTypeGenerator, ParameterTypeGenerator, PropertyTypeGenerator

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

    • AbstractTargetedGenerator

      protected AbstractTargetedGenerator(@NotNull @NotNull Class<T> valueType)
      Creates a new instance.
      Parameters:
      valueType - The type of generated values.
    • AbstractTargetedGenerator

      protected AbstractTargetedGenerator(@NotNull @NotNull Class<T> valueType, @NotNull @NotNull Generator generator)
      Creates a new instance.
      Parameters:
      valueType - The type of generated values.
      generator - The generator to use.
  • Method Details

    • getValueType

      @NotNull public @NotNull Class<T> getValueType()
      Returns the type of generated values.
      Returns:
      The type of generated values.
    • getDeclaredType

      public abstract Type getDeclaredType()
      Returns the declared type of the target.
      Returns:
      The declared type of the target.
    • getGenerator

      @NotNull protected @NotNull Generator getGenerator()
      Returns the generator to use.
      Returns:
      The generator to use.
    • defaultValue

      @NotNull public T defaultValue(@NotNull @NotNull Class<?>... groups)
      Returns the default value of the supported type.

      If the generator for the type of the target is a ParameterizableGenerator extracts the parameters from the constraints of the target when applying the specified validation groups.

      Specified by:
      defaultValue in interface TargetedGenerator<T>
      Parameters:
      groups - The validation groups to use when extracting the constraints of the target.
      Returns:
      The default value.
    • nullableDefaultValue

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

      If the generator for the type of the target is a ParameterizableGenerator extracts the parameters from the constraints of the target when applying the specified validation groups.

      This method should return null except for native types or targets annotated with NotNull.

      Specified by:
      nullableDefaultValue in interface TargetedGenerator<T>
      Parameters:
      groups - The validation groups to use when extracting the constraints of the target.
      Returns:
      The nullable default value for the specified type.
    • randomValue

      @NotNull public T randomValue(@NotNull @NotNull Class<?>... groups)
      Returns a random value of the supported type.

      If the generator for the type of the target is a ParameterizableGenerator extracts the parameters from the constraints of the target when applying the specified validation groups.

      Specified by:
      randomValue in interface TargetedGenerator<T>
      Parameters:
      groups - The validation groups to use when extracting the constraints of the target
      Returns:
      A random value.
    • nullableRandomValue

      public T nullableRandomValue(@NotNull @NotNull Class<?>... groups)
      Returns a random value of the specified type.

      If the generator for the type of the target is a ParameterizableGenerator extracts the parameters from the constraints of the target when applying the specified validation groups.

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

      Specified by:
      nullableRandomValue in interface TargetedGenerator<T>
      Parameters:
      groups - The validation groups to use when extracting the constraints of the target.
      Returns:
      A random nullable value.
      See Also:
    • getParameterSources

      @NotNull public @NotNull Object[] getParameterSources(@NotNull @NotNull Class<?>... groups)
      Returns the generation parameter sources to be used.

      The specified validation groups will be used to retrieve the constraints to use as sources.

      Specified by:
      getParameterSources in interface TargetedGenerator<T>
      Parameters:
      groups - The validation groups.
      Returns:
      The generation parameter sources.
    • getParameterSourceList

      @NotNull protected @NotNull List<Object> getParameterSourceList(@NotNull @NotNull Class<?>... groups)
      Returns the generation parameter sources to be used.

      The specified validation groups will be used to retrieve the constraints to use as sources.

      Parameters:
      groups - The validation groups .
      Returns:
      The generation parameter sources
    • getTargetConstraints

      @NotNull protected abstract @NotNull Collection<Annotation> getTargetConstraints(@NotNull @NotNull Class<?>... groups)
      Returns the constraints of the target for the specified validation groups.
      Parameters:
      groups - The validation groups to use when extracting the constraints of the target
      Returns:
      The constraints of the target
    • hashCode

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

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