Class AbstractGenerator<T>

java.lang.Object
org.instancio.internal.generator.AbstractGenerator<T>
Type Parameters:
T - type generated by this generator
All Implemented Interfaces:
Generator<T>, GeneratorSpec<T>, NullableGeneratorSpec<T>
Direct Known Subclasses:
AbstractNumericSequenceGenerator, AbstractRandomNumberGeneratorSpec, ArrayGenerator, AtomicBooleanGenerator, BaseModCheckGenerator, BooleanGenerator, CalendarGenerator, CharacterGenerator, ClassGenerator, CollectionGenerator, CsvGenerator, DateGenerator, DurationGenerator, EmailGenerator, EmitGenerator, EnumGenerator, EnumSetGenerator, FileGenerator, HashGenerator, InetAddressGenerator, InstantGenerator, Ip4Generator, LocalDateGenerator, LocalDateTimeGenerator, LocaleGenerator, LocalTimeGenerator, LoremIpsumGenerator, MapEntryGenerator, MapGenerator, MonthDayGenerator, OffsetDateTimeGenerator, OffsetTimeGenerator, OneOfArrayGenerator, OneOfCollectionGenerator, OptionalGenerator, PathGenerator, PeriodGenerator, SqlDateGenerator, StringBuilderGenerator, StringGenerator, TextPatternGenerator, TimestampGenerator, TimeZoneGenerator, URIGenerator, URLGenerator, UUIDGenerator, UUIDStringGenerator, XMLGregorianCalendarGenerator, YearGenerator, YearMonthGenerator, ZonedDateTimeGenerator, ZoneIdGenerator, ZoneOffsetGenerator

@InternalApi public abstract class AbstractGenerator<T> extends Object implements Generator<T>, NullableGeneratorSpec<T>
Base class for all internal generators.
  • Constructor Details

  • Method Details

    • apiMethod

      public abstract String apiMethod()
      Returns the public API method name of the generator spec. The returned name is used for reporting validation errors.
      Returns:
      spec name if defined, or null otherwise
    • tryGenerateNonNull

      protected abstract T tryGenerateNonNull(Random random)
      Makes the best effort to return a non-null value. However, in certain cases this method will produce a null.
      Parameters:
      random - for generating the value
      Returns:
      generated value, either a null or non-null
    • generate

      public T generate(Random random)
      Base implementation that handles nullable values.
      Specified by:
      generate in interface Generator<T>
      Parameters:
      random - generating random the value
      Returns:
      generated value, either a null or non-null
    • nullable

      public NullableGeneratorSpec<T> nullable()
      Description copied from interface: NullableGeneratorSpec
      Indicates that null value can be generated.
      Specified by:
      nullable in interface NullableGeneratorSpec<T>
      Returns:
      spec builder
    • nullable

      public NullableGeneratorSpec<T> nullable(boolean isNullable)
    • isNullable

      public final boolean isNullable()
    • getContext

      public GeneratorContext getContext()
    • hints

      public Hints hints()
      Description copied from interface: Generator
      Hints provided by the generator to the engine.

      The most important hint for custom generators is AfterGenerate. This hint indicates whether the object created by this generator:

      • should be populated (for example, if it has null fields)
      • can be modified using selectors

      For example, setting the hint to AfterGenerate.POPULATE_NULLS will cause Instancio to populate null fields on the object returned by this generator:

      
         @Override
         public Hints hints() {
             return Hints.afterGenerate(AfterGenerate.POPULATE_NULLS);
         }
       

      If the action is not specified, default behaviour will be based on the AfterGenerate value configured in the Settings using the key Keys.AFTER_GENERATE_HINT.

      In addition, the following hints can be provided for populating data structures:

      Specified by:
      hints in interface Generator<T>
      Returns:
      hints from this generator to the engine
      See Also: