Class EmitGenerator<T>
java.lang.Object
org.instancio.internal.generator.AbstractGenerator<T>
org.instancio.internal.generator.misc.EmitGenerator<T>
- All Implemented Interfaces:
Generator<T>,GeneratorSpec<T>,EmitGeneratorSpec<T>,NullableGeneratorSpec<T>
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the public API method name of the generator spec.getItems()booleanhasMore()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).booleanEmit givenitemnnumber of times.Emit givenitems.shuffle()Specifies that items should be emitted in random order.protected TtryGenerateNonNull(Random random) Makes the best effort to return a non-null value.Specifies thatnullshould 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:AbstractGeneratorReturns the public API method name of the generator spec. The returned name is used for reporting validation errors.- Specified by:
apiMethodin classAbstractGenerator<T>- Returns:
- spec name if defined, or
nullotherwise
-
items
Description copied from interface:EmitGeneratorSpecEmit givenitems.This method can be invoked multiple times to add more items to emit.
- Specified by:
itemsin interfaceEmitGeneratorSpec<T>- Parameters:
items- to emit,nullarray is not allowed, but the array itself may containnullelements unless the target is aMapkey- Returns:
- spec builder
- See Also:
-
item
Description copied from interface:EmitGeneratorSpecEmit givenitemnnumber of times.This method can be invoked multiple times and combined with
EmitGeneratorSpec.items(Object[]).- Specified by:
itemin interfaceEmitGeneratorSpec<T>- Parameters:
item- to emit,nullallowed unless the target is aMapkeyn- number of times the item should be emitted; must not be negative- Returns:
- spec builder
- See Also:
-
shuffle
Description copied from interface:EmitGeneratorSpecSpecifies that items should be emitted in random order.- Specified by:
shufflein interfaceEmitGeneratorSpec<T>- Returns:
- spec builder
-
ignoreUnused
Description copied from interface:EmitGeneratorSpecSpecifies that if any of the provided items were not emitted, they should be ignored (the default is to throw an exception).- Specified by:
ignoreUnusedin interfaceEmitGeneratorSpec<T>- Returns:
- spec builder
-
whenEmptyEmitNull
Description copied from interface:EmitGeneratorSpecSpecifies thatnullshould be generated if an insufficient number of items were provided.- Specified by:
whenEmptyEmitNullin interfaceEmitGeneratorSpec<T>- Returns:
- spec builder
-
whenEmptyEmitRandom
Description copied from interface:EmitGeneratorSpecSpecifies that a random value should be generated if an insufficient number of items were provided.- Specified by:
whenEmptyEmitRandomin interfaceEmitGeneratorSpec<T>- Returns:
- spec builder
-
whenEmptyThrowException
Description copied from interface:EmitGeneratorSpecSpecifies that an exception should be raised if an insufficient number of items were provided.- Specified by:
whenEmptyThrowExceptionin interfaceEmitGeneratorSpec<T>- Returns:
- spec builder
-
getWhenEmptyAction
-
hasMore
public boolean hasMore() -
getItems
-
isIgnoreUnused
public boolean isIgnoreUnused() -
tryGenerateNonNull
Description copied from class:AbstractGeneratorMakes the best effort to return a non-null value. However, in certain cases this method will produce anull.- Specified by:
tryGenerateNonNullin classAbstractGenerator<T>- Parameters:
random- for generating the value- Returns:
- generated value, either a null or non-null
-
hints
Description copied from interface:GeneratorHints 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
nullfields) - can be modified using selectors
For example, setting the hint to
AfterGenerate.POPULATE_NULLSwill cause Instancio to populatenullfields 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
AfterGeneratevalue configured in theSettingsusing 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
-