Class MapGenerator<K,V>
java.lang.Object
org.instancio.internal.generator.AbstractGenerator<Map<K,V>>
org.instancio.internal.generator.util.MapGenerator<K,V>
- All Implemented Interfaces:
Generator<Map<K,,V>> GeneratorSpec<Map<K,,V>> MapGeneratorSpec<K,,V> NullableGeneratorSpec<Map<K,,V>> SubtypeGeneratorSpec<Map<K,V>>
- Direct Known Subclasses:
MapGeneratorSpecImpl
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected Class<?>protected intprotected intprotected booleanprotected boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the public API method name of the generator spec.hints()Hints provided by the generator to the engine.maxSize(int size) Maximum size of map to generate.minSize(int size) Minimum size of map to generate.nullable()Indicates thatnullvalue can be generated.nullable(boolean isNullable) Indicates thatnullvalues can be generated for map keys.Indicates thatnullvalues can be generated for map values.size(int size) Size of map to generate.Specifies the type of map that should be generated.tryGenerateNonNull(Random random) Makes the best effort to return a non-null value.Adds given key/value pair to the generated map.final MapGeneratorSpec<K,V> Adds given keys to the map in the order they are provided.Methods inherited from class org.instancio.internal.generator.AbstractGenerator
generate, getContext, isNullable
-
Field Details
-
minSize
protected int minSize -
maxSize
protected int maxSize -
nullableKeys
protected boolean nullableKeys -
nullableValues
protected boolean nullableValues -
mapType
-
isDelegating
protected boolean isDelegating
-
-
Constructor Details
-
MapGenerator
-
-
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<Map<K,V>> - Returns:
- spec name if defined, or
nullotherwise
-
subtype
Description copied from interface:MapGeneratorSpecSpecifies the type of map that should be generated.- Specified by:
subtypein interfaceMapGeneratorSpec<K,V> - Specified by:
subtypein interfaceSubtypeGeneratorSpec<K>- Parameters:
type- of collection to generate- Returns:
- spec builder
-
size
Description copied from interface:MapGeneratorSpecSize of map to generate.- Specified by:
sizein interfaceMapGeneratorSpec<K,V> - Parameters:
size- of map- Returns:
- spec builder
-
minSize
Description copied from interface:MapGeneratorSpecMinimum size of map to generate.- Specified by:
minSizein interfaceMapGeneratorSpec<K,V> - Parameters:
size- minimum size (inclusive)- Returns:
- spec builder
-
maxSize
Description copied from interface:MapGeneratorSpecMaximum size of map to generate.- Specified by:
maxSizein interfaceMapGeneratorSpec<K,V> - Parameters:
size- maximum size (inclusive)- Returns:
- spec builder
-
nullable
Description copied from interface:NullableGeneratorSpecIndicates thatnullvalue can be generated.- Specified by:
nullablein interfaceMapGeneratorSpec<K,V> - Specified by:
nullablein interfaceNullableGeneratorSpec<K>- Overrides:
nullablein classAbstractGenerator<Map<K,V>> - Returns:
- spec builder
-
nullable
- Overrides:
nullablein classAbstractGenerator<Map<K,V>>
-
nullableKeys
Description copied from interface:MapGeneratorSpecIndicates thatnullvalues can be generated for map keys.- Specified by:
nullableKeysin interfaceMapGeneratorSpec<K,V> - Returns:
- spec builder
-
nullableValues
Description copied from interface:MapGeneratorSpecIndicates thatnullvalues can be generated for map values.- Specified by:
nullableValuesin interfaceMapGeneratorSpec<K,V> - Returns:
- spec builder
-
with
Description copied from interface:MapGeneratorSpecAdds given key/value pair to the generated map. Note that the entry is added after the map has been generated.Example:
// will generate a map of size 5 (3 random + 2 custom entries) generate(field("someMap"), gen -> gen.map() .size(3) .with("key1", "value1") .with("key2", "value2")- Specified by:
within interfaceMapGeneratorSpec<K,V> - Parameters:
key- to addvalue- to add- Returns:
- spec builder
- See Also:
-
withKeys
Description copied from interface:MapGeneratorSpecAdds given keys to the map in the order they are provided.If the resulting map size is equal to the number of specified keys, then the map will contain only the specified keys and no randomly generated keys.
Examples:
// will generate a map of size 1 containing only "key1" generate(field("someMap"), gen -> gen.map().size(1).withKeys("key1", "key2") // will generate a map of size 2 containing "key1" and "key2" generate(field("someMap"), gen -> gen.map().size(2).withKeys("key1", "key2") // will generate a map of size 5 containing "key1", "key2", and 3 randomly generated keys generate(field("someMap"), gen -> gen.map().size(5).withKeys("key1", "key2")- Specified by:
withKeysin interfaceMapGeneratorSpec<K,V> - Parameters:
keys- to add- Returns:
- spec builder
- See Also:
-
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<Map<K,V>> - 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
-