Class AbstractPrimitiveGenerator<T>

java.lang.Object
dev.orne.test.rnd.AbstractGenerator
dev.orne.test.rnd.AbstractTypedGenerator<T>
dev.orne.test.rnd.generators.AbstractPrimitiveGenerator<T>
Type Parameters:
T - The primitive wrapper type
All Implemented Interfaces:
Generator, TypedGenerator<T>
Direct Known Subclasses:
BooleanGenerator, ByteGenerator, CharacterGenerator, DoubleGenerator, FloatGenerator, IntegerGenerator, LongGenerator, ShortGenerator

@API(status=STABLE, since="0.1") public abstract class AbstractPrimitiveGenerator<T> extends AbstractTypedGenerator<T>
Abstract generator implementation for primitive types.
Since:
0.1
Version:
1.0, 2022-10
Author:
(w) Iker Hernaez
  • Constructor Details

    • AbstractPrimitiveGenerator

      protected AbstractPrimitiveGenerator()
      Crates a new instance.

      Infers generated values type from the generic type arguments of this instance class. The class must extend AbstractPrimitiveGenerator specifying the generic types.

      Example:

       class MyLongGenerator
       extends AbstractPrimitiveGenerator<Long> {
           ...
       }
       
    • AbstractPrimitiveGenerator

      protected AbstractPrimitiveGenerator(@NotNull @NotNull Class<T> valueType)
      Crates a new instance.
      Parameters:
      valueType - The type of generated values
  • Method Details

    • supports

      public boolean supports(@NotNull @NotNull Class<?> type)
      Checks if values of the specified type can be generated by this instance.
      Specified by:
      supports in interface Generator
      Overrides:
      supports in class AbstractTypedGenerator<T>
      Parameters:
      type - The type to check.
      Returns:
      If values of the specified type can be generated.
    • nullableDefaultValue

      public <R> R nullableDefaultValue(@NotNull @NotNull Class<R> 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:
      R - The requested value type.
      Parameters:
      type - The requested value type.
      Returns:
      The nullable default value for the specified type.
    • randomNull

      public boolean randomNull(@NotNull @NotNull Class<?> type)
      Determines if the value must be null based on the probability of null values.

      Overriding classes can use the type parameter to detect non nullable types (like primitives).

      Overrides:
      randomNull in class AbstractGenerator
      Parameters:
      type - The requested value type
      Returns:
      If the value must be null
      See Also: