Interface Generator<T>

Type Parameters:
T - type to generate
All Superinterfaces:
GeneratorSpec<T>
All Known Implementing Classes:
AbstractGenerator, AbstractRandomComparableNumberGeneratorSpec, AbstractRandomNumberGeneratorSpec, ArrayGenerator, AtomicIntegerGenerator, AtomicLongGenerator, BigDecimalGenerator, BigIntegerGenerator, BooleanGenerator, ByteGenerator, CalendarGenerator, CharacterGenerator, CollectionGenerator, CollectionGeneratorSpecImpl, ConcurrentHashMapGenerator, ConcurrentSkipListMapGenerator, DateGenerator, DoubleGenerator, DurationGenerator, EnumGenerator, EnumSetGenerator, FloatGenerator, GeneratorDecorator, HashSetGenerator, InstantGenerator, InstantiatingGenerator, IntegerGenerator, LocalDateGenerator, LocalDateTimeGenerator, LocalTimeGenerator, LongGenerator, LoremIpsumGenerator, MapGenerator, MapGeneratorSpecImpl, OneOfArrayGenerator, OneOfCollectionGenerator, OptionalGenerator, PeriodGenerator, ShortGenerator, SqlDateGenerator, StringBuilderGenerator, StringGenerator, SupplierAdapter, TextPatternGenerator, TimestampGenerator, TreeMapGenerator, TreeSetGenerator, UUIDGenerator, UUIDStringGenerator, XMLGregorianCalendarGenerator, YearGenerator, YearMonthGenerator, ZonedDateTimeGenerator
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Generator<T> extends GeneratorSpec<T>
A class for generating values of a specific type.
Since:
1.0.1
  • Method Summary

    Modifier and Type
    Method
    Description
    generate(Random random)
    Returns a generated value.
    default @Nullable Hints
    Hints provided by the generator to the engine.
  • Method Details

    • generate

      @Nullable T generate(Random random)
      Returns a generated value.

      If this method produces random data, the data needs to be generated using the provided Random instance. This ensures generated values are reproducible for a given seed value.

      Parameters:
      random - provider for generating random values
      Returns:
      generated value or null if value is nullable, could not be generated, or generation is delegated to the engine
    • hints

      @Nullable default @Nullable Hints hints()
      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:

      Returns:
      hints from this generator to the engine
      Since:
      2.0.0
      See Also: