Interface Generator<T>
- Type Parameters:
T
- type to generate
- All Superinterfaces:
GeneratorSpec<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
- Since:
- 1.0.1
-
Method Summary
-
Method Details
-
init
An optional method for generators that need to initialise state before generating values.Note: this method is guaranteed to be called before
generate(Random)
, however, there is no guarantee as to the number of times it will be invoked. It is possible forinit()
to be called multiple times for a given generator instance.- Parameters:
context
- generator context- Since:
- 2.13.0
-
generate
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
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:
- Returns:
- hints from this generator to the engine
- Since:
- 2.0.0
- See Also:
- should be populated (for example, if it has
-