Class CollectionGenerator<T>
java.lang.Object
org.instancio.internal.generator.AbstractGenerator<Collection<T>>
org.instancio.internal.generator.util.CollectionGenerator<T>
- All Implemented Interfaces:
Generator<Collection<T>>
,GeneratorSpec<Collection<T>>
,CollectionGeneratorSpec<T>
- Direct Known Subclasses:
CollectionGeneratorSpecImpl
public class CollectionGenerator<T>
extends AbstractGenerator<Collection<T>>
implements CollectionGeneratorSpec<T>
-
Field Summary
Modifier and TypeFieldDescriptionprotected Class<?>
protected boolean
protected int
protected int
protected boolean
protected boolean
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the public API method name of the generator spec.Returns a generated value.hints()
Hints provided by the generator to the engine.maxSize
(int size) Maximum size of collection to generate.minSize
(int size) Minimum size of collection to generate.nullable()
Indicates thatnull
value can be generated for the collection.Indicates thatnull
values can be generated for collection elements.size
(int size) Size of collection to generate.Specifies the type of collection that should be generated.final CollectionGeneratorSpec<T>
Adds given elements to the generated collection at random positions.Methods inherited from class org.instancio.internal.generator.AbstractGenerator
getContext
-
Field Details
-
minSize
protected int minSize -
maxSize
protected int maxSize -
nullable
protected boolean nullable -
nullableElements
protected boolean nullableElements -
withElements
-
collectionType
-
isDelegating
protected boolean isDelegating
-
-
Constructor Details
-
CollectionGenerator
-
-
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<Collection<T>>
- Returns:
- spec name if defined, or
null
otherwise
-
size
Description copied from interface:CollectionGeneratorSpec
Size of collection to generate.- Specified by:
size
in interfaceCollectionGeneratorSpec<T>
- Parameters:
size
- of collection- Returns:
- spec builder
-
minSize
Description copied from interface:CollectionGeneratorSpec
Minimum size of collection to generate.- Specified by:
minSize
in interfaceCollectionGeneratorSpec<T>
- Parameters:
size
- minimum size (inclusive)- Returns:
- spec builder
-
maxSize
Description copied from interface:CollectionGeneratorSpec
Maximum size of collection to generate.- Specified by:
maxSize
in interfaceCollectionGeneratorSpec<T>
- Parameters:
size
- maximum size (inclusive)- Returns:
- spec builder
-
nullable
Description copied from interface:CollectionGeneratorSpec
Indicates thatnull
value can be generated for the collection.- Specified by:
nullable
in interfaceCollectionGeneratorSpec<T>
- Returns:
- spec builder
-
nullableElements
Description copied from interface:CollectionGeneratorSpec
Indicates thatnull
values can be generated for collection elements.- Specified by:
nullableElements
in interfaceCollectionGeneratorSpec<T>
- Returns:
- spec builder
-
subtype
Description copied from interface:CollectionGeneratorSpec
Specifies the type of collection that should be generated.- Specified by:
subtype
in interfaceCollectionGeneratorSpec<T>
- Parameters:
type
- of collection to generate- Returns:
- spec builder
-
with
Description copied from interface:CollectionGeneratorSpec
Adds given elements to the generated collection at random positions. Note that the elements are added after the collection has been generated.Example:
// will generate a collection of size 5 generate(field("someList"), gen -> gen.collection().size(3).with("element1", "element2")
- Specified by:
with
in interfaceCollectionGeneratorSpec<T>
- Parameters:
elements
- to add- Returns:
- spec builder
-
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. -
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:
- Specified by:
hints
in interfaceGenerator<T>
- Overrides:
hints
in classAbstractGenerator<Collection<T>>
- Returns:
- hints from this generator to the engine
- See Also:
- should be populated (for example, if it has
-