Class GeneratorDecorator<T>
java.lang.Object
org.instancio.internal.generator.misc.GeneratorDecorator<T>
- Type Parameters:
T
- generated type
- All Implemented Interfaces:
Generator<T>
,GeneratorSpec<T>
- Direct Known Subclasses:
SupplierAdapter
Decorator for generators that might be missing hints.
- Since:
- 2.14.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Generator<T>
Decorates suppliers fromInstancioApi.supply(TargetSelector, Generator)
.static <T> Generator<T>
decorateIfNullAfterGenerate
(Generator<T> generator, AfterGenerate defaultAfterGenerate) Decorates thegenerator
with thedefaultAfterGenerate
action if the generator does not specify the action in its hints.final T
Returns a generated value.final void
init
(GeneratorContext context) An optional method for generators that need to initialise state before generating values.static <T> Generator<T>
replaceHints
(Generator<T> generator, Hints hints) Decorates thegenerator
with the specifiedhints
.
-
Constructor Details
-
GeneratorDecorator
-
-
Method Details
-
init
Description copied from interface:Generator
An optional method for generators that need to initialise state before generating values.Note: this method is guaranteed to be called before
Generator.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. -
generate
Description copied from interface:Generator
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. -
getDelegate
-
decorate
Decorates suppliers fromInstancioApi.supply(TargetSelector, Generator)
.- Type Parameters:
T
- generated type- Parameters:
supplier
- to decorate with hints- Returns:
- generator backed by the given supplier
-
replaceHints
Decorates thegenerator
with the specifiedhints
. The original hints will be ignored.- Type Parameters:
T
- generated type- Parameters:
generator
- to decorate with new hintshints
- replacement hints- Returns:
- generator with substituted hints
-
decorateIfNullAfterGenerate
public static <T> Generator<T> decorateIfNullAfterGenerate(Generator<T> generator, AfterGenerate defaultAfterGenerate) Decorates thegenerator
with thedefaultAfterGenerate
action if the generator does not specify the action in its hints. Retains all the other hints defined by thegenerator
.- Type Parameters:
T
- generated type- Parameters:
generator
- to decorate with the actiondefaultAfterGenerate
- the default action- Returns:
- generator with updated hints if no action was specified in the original hints
-