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, CreditCardNumberGenerator, DateGenerator, DoubleGenerator, DurationGenerator, EanGenerator, EmailAddressGenerator, EnumGenerator, EnumSetGenerator, FileGenerator, FloatGenerator, GeneratorDecorator, InstantGenerator, InstantiatingGenerator, IntegerGenerator, IsbnGenerator, LocalDateGenerator, LocalDateTimeGenerator, LocaleGenerator, LocalTimeGenerator, LongGenerator, LoremIpsumGenerator, LuhnGenerator, MapEntryGenerator, MapGenerator, MapGeneratorSpecImpl, MonthDayGenerator, OffsetDateTimeGenerator, OffsetTimeGenerator, OneOfArrayGenerator, OneOfCollectionGenerator, OptionalGenerator, PathGenerator, PeriodGenerator, ShortGenerator, SqlDateGenerator, StringBuilderGenerator, StringGenerator, SupplierAdapter, TextPatternGenerator, TimestampGenerator, URIGenerator, URLGenerator, UUIDGenerator, UUIDStringGenerator, XMLGregorianCalendarGenerator, YearGenerator, YearMonthGenerator, ZonedDateTimeGenerator, ZoneIdGenerator, ZoneOffsetGenerator
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 Hints
    Hints provided by the generator to the engine.
  • Method Details

    • generate

      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

      default 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: