Interface Generator

All Known Subinterfaces:
ParameterizableGenerator, TypedGenerator<T>, TypedParameterizableGenerator<T>
All Known Implementing Classes:
AbstractGenerator, AbstractParameterizableGenerator, AbstractPrimitiveGenerator, AbstractTypedGenerator, AbstractTypedParameterizableGenerator, AnnotatedMethodGenerator, ArrayGenerator, BigDecimalGenerator, BigIntegerGenerator, BooleanGenerator, ByteGenerator, CalendarGenerator, CharacterGenerator, CharsetGenerator, ChronologyGenerator, ClockGenerator, ConstructorGenerator, CurrencyGenerator, DateGenerator, DoubleGenerator, DurationGenerator, EnumGenerator, ExecutableGenerator, FactoryMethodGenerator, FileGenerator, FloatGenerator, Generators.MissingGenerator, InstantGenerator, IntegerGenerator, ListGenerator, LocalDateGenerator, LocalDateTimeGenerator, LocaleGenerator, LocalTimeGenerator, LongGenerator, MapGenerator, MonthDayGenerator, OffsetDateTimeGenerator, OffsetTimeGenerator, PathGenerator, PeriodGenerator, SetGenerator, ShortGenerator, StringGenerator, TimeZoneGenerator, URIGenerator, URLGenerator, UUIDGenerator, YearGenerator, YearMonthGenerator, ZonedDateTimeGenerator, ZoneIdGenerator, ZoneOffsetGenerator

@API(status=STABLE, since="0.1") public interface Generator
Interface for random value generators.
Since:
0.1
Version:
1.0, 2021-03
Author:
(w) Iker Hernaez
  • Method Summary

    Modifier and Type
    Method
    Description
    default @NotNull ParameterizableGenerator
    Returns this generator as a parameterizable generator.
    <T> T
    defaultValue(@NotNull Class<T> type)
    Returns the default value for the specified type.
    default int
    Returns the priority of this generator.
    <T> T
    nullableDefaultValue(@NotNull Class<T> type)
    Returns the default value for the specified type allowing null values.
    <T> T
    nullableRandomValue(@NotNull Class<T> type)
    Returns a random value of the specified type allowing null values.
    <T> T
    randomValue(@NotNull Class<T> type)
    Returns a random value of the specified type.
    boolean
    supports(@NotNull Class<?> type)
    Checks if values of the specified type can be generated by this instance.
  • Method Details

    • supports

      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 <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.
      Throws:
      UnsupportedValueTypeException - If the specified type is not supported.
      GenerationException - If an error occurs generating the value
    • nullableDefaultValue

      <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.

      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      Returns:
      The nullable default value for the specified type.
      Throws:
      UnsupportedValueTypeException - If the specified type is not supported.
      GenerationException - If an error occurs generating the value
    • randomValue

      @NotNull <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.
      Throws:
      UnsupportedValueTypeException - If the specified type is not supported.
      GenerationException - If an error occurs generating the value
    • nullableRandomValue

      <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().

      Type Parameters:
      T - The requested value type.
      Parameters:
      type - The requested value type.
      Returns:
      A random nullable value for the specified type.
      Throws:
      UnsupportedValueTypeException - If the specified type is not supported.
      GenerationException - If an error occurs generating the value
      See Also:
    • getPriority

      default int getPriority()
      Returns the priority of this generator.
      Returns:
      The priority of this generator
    • asParameterizable

      @NotNull default @NotNull ParameterizableGenerator asParameterizable()
      Returns this generator as a parameterizable generator.

      If the generator is not parameterizable throws an exception.

      Returns:
      This generator as a parameterizable generator.
      Throws:
      GeneratorNotParameterizableException - If the generator is not parameterizable.