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
,DateGenerator
,DurationGenerator
,EanGenerator
,EmailGenerator
,EnumGenerator
,EnumSetGenerator
,FileGenerator
,HashGenerator
,InstantGenerator
,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
-
Method Summary
Modifier and TypeMethodDescriptionabstract String
Returns the public API method name of the generator spec.final T
Base implementation that handles nullable values.hints()
Hints provided by the generator to the engine.final boolean
nullable()
Indicates thatnull
value can be generated.nullable
(boolean isNullable) protected abstract T
tryGenerateNonNull
(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
null
otherwise
-
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:NullableGeneratorSpec
Indicates thatnull
value can be generated.- Specified by:
nullable
in interfaceNullableGeneratorSpec<T>
- Returns:
- spec builder
-
nullable
-
isNullable
public final boolean isNullable() -
getContext
-
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 populatenull
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 theSettings
using 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
-