Package org.instancio.internal.generator
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:
AbstractRandomNumberGeneratorSpec,ArrayGenerator,BooleanGenerator,CalendarGenerator,CharacterGenerator,CollectionGenerator,CreditCardNumberGenerator,CsvGenerator,DateGenerator,DurationGenerator,EanGenerator,EmailGenerator,EmitGenerator,EnumGenerator,EnumSetGenerator,FileGenerator,HashGenerator,InetAddressGenerator,InstantGenerator,Ip4Generator,IsbnGenerator,LocalDateGenerator,LocalDateTimeGenerator,LocaleGenerator,LocalTimeGenerator,LoremIpsumGenerator,LuhnGenerator,MapEntryGenerator,MapGenerator,MonthDayGenerator,OffsetDateTimeGenerator,OffsetTimeGenerator,OneOfArrayGenerator,OneOfCollectionGenerator,OptionalGenerator,PathGenerator,PeriodGenerator,SqlDateGenerator,StringBuilderGenerator,StringGenerator,TextPatternGenerator,TimestampGenerator,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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract StringReturns the public API method name of the generator spec.Base implementation that handles nullable values.hints()Hints provided by the generator to the engine.final booleannullable()Indicates thatnullvalue can be generated.nullable(boolean isNullable) protected abstract TtryGenerateNonNull(Random random) Makes the best effort to return a non-null value.
-
Constructor Details
-
AbstractGenerator
-
-
Method Details
-
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
nullotherwise
-
tryGenerateNonNull
Makes the best effort to return a non-null value. However, in certain cases this method will produce anull.- Parameters:
random- for generating the value- Returns:
- generated value, either a null or non-null
-
generate
Base implementation that handles nullable values. -
nullable
Description copied from interface:NullableGeneratorSpecIndicates thatnullvalue can be generated.- Specified by:
nullablein interfaceNullableGeneratorSpec<T>- Returns:
- spec builder
-
nullable
-
isNullable
public final boolean isNullable() -
getContext
-
hints
Description copied from interface:GeneratorHints 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
nullfields) - can be modified using selectors
For example, setting the hint to
AfterGenerate.POPULATE_NULLSwill cause Instancio to populatenullfields 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
AfterGeneratevalue configured in theSettingsusing the keyKeys.AFTER_GENERATE_HINT.In addition, the following hints can be provided for populating data structures:
- should be populated (for example, if it has
-