Class OptionalGenerator<T>
java.lang.Object
org.instancio.internal.generator.AbstractGenerator<Optional<T>>
org.instancio.internal.generator.util.OptionalGenerator<T>
- All Implemented Interfaces:
Generator<Optional<T>>
,GeneratorSpec<Optional<T>>
,NullableGeneratorSpec<Optional<T>>
,OptionalGeneratorSpec<T>
public class OptionalGenerator<T>
extends AbstractGenerator<Optional<T>>
implements OptionalGeneratorSpec<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSpecifies that an emptyOptional
can be generated.Returns the public API method name of the generator spec.hints()
Hints provided by the generator to the engine.tryGenerateNonNull
(Random random) Makes the best effort to return a non-null value.Methods inherited from class org.instancio.internal.generator.AbstractGenerator
generate, getContext, isNullable, nullable, nullable
-
Constructor Details
-
OptionalGenerator
-
-
Method Details
-
apiMethod
Description copied from class:AbstractGenerator
Returns the public API method name of the generator spec. The returned name is used for reporting validation errors.- Specified by:
apiMethod
in classAbstractGenerator<Optional<T>>
- Returns:
- spec name if defined, or
null
otherwise
-
allowEmpty
Description copied from interface:OptionalGeneratorSpec
Specifies that an emptyOptional
can be generated.- Specified by:
allowEmpty
in interfaceOptionalGeneratorSpec<T>
- Returns:
- spec builder
-
tryGenerateNonNull
Description copied from class:AbstractGenerator
Makes the best effort to return a non-null value. However, in certain cases this method will produce anull
.- Specified by:
tryGenerateNonNull
in classAbstractGenerator<Optional<T>>
- Parameters:
random
- for generating the value- Returns:
- generated value, either a null or non-null
-
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
-