Class EmitGenerator<T>
- All Implemented Interfaces:
Generator<T>
,GeneratorSpec<T>
,EmitGeneratorSpec<T>
,NullableGeneratorSpec<T>
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the public API method name of the generator spec.getItems()
boolean
hasMore()
hints()
Hints provided by the generator to the engine.Specifies that if any of the provided items were not emitted, they should be ignored (the default is to throw an exception).boolean
Emit givenitem
n
number of times.Emit givenitems
.Emit givenitems
.shuffle()
Specifies that items should be emitted in random order.protected T
tryGenerateNonNull
(Random random) Makes the best effort to return a non-null value.Specifies thatnull
should be generated if an insufficient number of items were provided.Specifies that a random value should be generated if an insufficient number of items were provided.Specifies that an exception should be raised if an insufficient number of items were provided.Methods inherited from class org.instancio.internal.generator.AbstractGenerator
generate, getContext, isNullable, nullable, nullable
-
Constructor Details
-
EmitGenerator
-
-
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<T>
- Returns:
- spec name if defined, or
null
otherwise
-
items
Description copied from interface:EmitGeneratorSpec
Emit givenitems
.This method can be invoked multiple times to add more items to emit.
- Specified by:
items
in interfaceEmitGeneratorSpec<T>
- Parameters:
items
- to emit,null
array is not allowed, but the array itself may containnull
elements unless the target is aMap
key- Returns:
- spec builder
- See Also:
-
items
Description copied from interface:EmitGeneratorSpec
Emit givenitems
.This method can be invoked multiple times to add more items to emit.
- Specified by:
items
in interfaceEmitGeneratorSpec<T>
- Parameters:
items
- to emit,null
iterable is not allowed, but the iterable itself may containnull
elements unless the target is aMap
key- Returns:
- spec builder
- See Also:
-
item
Description copied from interface:EmitGeneratorSpec
Emit givenitem
n
number of times.This method can be invoked multiple times and combined with
EmitGeneratorSpec.items(Object[])
.- Specified by:
item
in interfaceEmitGeneratorSpec<T>
- Parameters:
item
- to emit,null
allowed unless the target is aMap
keyn
- number of times the item should be emitted; must not be negative- Returns:
- spec builder
- See Also:
-
shuffle
Description copied from interface:EmitGeneratorSpec
Specifies that items should be emitted in random order.- Specified by:
shuffle
in interfaceEmitGeneratorSpec<T>
- Returns:
- spec builder
-
ignoreUnused
Description copied from interface:EmitGeneratorSpec
Specifies that if any of the provided items were not emitted, they should be ignored (the default is to throw an exception).- Specified by:
ignoreUnused
in interfaceEmitGeneratorSpec<T>
- Returns:
- spec builder
-
whenEmptyEmitNull
Description copied from interface:EmitGeneratorSpec
Specifies thatnull
should be generated if an insufficient number of items were provided.- Specified by:
whenEmptyEmitNull
in interfaceEmitGeneratorSpec<T>
- Returns:
- spec builder
-
whenEmptyEmitRandom
Description copied from interface:EmitGeneratorSpec
Specifies that a random value should be generated if an insufficient number of items were provided.- Specified by:
whenEmptyEmitRandom
in interfaceEmitGeneratorSpec<T>
- Returns:
- spec builder
-
whenEmptyThrowException
Description copied from interface:EmitGeneratorSpec
Specifies that an exception should be raised if an insufficient number of items were provided.- Specified by:
whenEmptyThrowException
in interfaceEmitGeneratorSpec<T>
- Returns:
- spec builder
-
getWhenEmptyAction
-
hasMore
public boolean hasMore() -
getItems
-
isIgnoreUnused
public boolean isIgnoreUnused() -
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<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
-