Class MapGenerator<K,V>
- All Implemented Interfaces:
Generator<Map<K,
,V>> GeneratorSpec<Map<K,
,V>> MapGeneratorSpec<K,
V>
- Direct Known Subclasses:
ConcurrentHashMapGenerator
,ConcurrentSkipListMapGenerator
,MapGeneratorSpecImpl
,TreeMapGenerator
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected Class<?>
protected int
protected int
protected boolean
protected boolean
protected boolean
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns a generated value.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 thatnull
value can be generated for the map.Indicates thatnull
values can be generated for map keys.Indicates thatnull
values can be generated for map values.size
(int size) Size of map to generate.Specifies the type of map that should be generated.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
getContext
-
Field Details
-
minSize
protected int minSize -
maxSize
protected int maxSize -
nullable
protected boolean nullable -
nullableKeys
protected boolean nullableKeys -
nullableValues
protected boolean nullableValues -
mapType
-
isDelegating
protected boolean isDelegating
-
-
Constructor Details
-
MapGenerator
-
-
Method Details
-
subtype
Description copied from interface:MapGeneratorSpec
Specifies the type of map that should be generated.- Specified by:
subtype
in interfaceMapGeneratorSpec<K,
V> - Parameters:
type
- of collection to generate- Returns:
- spec builder
-
size
Description copied from interface:MapGeneratorSpec
Size of map to generate.- Specified by:
size
in interfaceMapGeneratorSpec<K,
V> - Parameters:
size
- of map- Returns:
- spec builder
-
minSize
Description copied from interface:MapGeneratorSpec
Minimum size of map to generate.- Specified by:
minSize
in interfaceMapGeneratorSpec<K,
V> - Parameters:
size
- minimum size (inclusive)- Returns:
- spec builder
-
maxSize
Description copied from interface:MapGeneratorSpec
Maximum size of map to generate.- Specified by:
maxSize
in interfaceMapGeneratorSpec<K,
V> - Parameters:
size
- maximum size (inclusive)- Returns:
- spec builder
-
nullable
Description copied from interface:MapGeneratorSpec
Indicates thatnull
value can be generated for the map.- Specified by:
nullable
in interfaceMapGeneratorSpec<K,
V> - Returns:
- spec builder
-
nullableKeys
Description copied from interface:MapGeneratorSpec
Indicates thatnull
values can be generated for map keys.- Specified by:
nullableKeys
in interfaceMapGeneratorSpec<K,
V> - Returns:
- spec builder
-
nullableValues
Description copied from interface:MapGeneratorSpec
Indicates thatnull
values can be generated for map values.- Specified by:
nullableValues
in interfaceMapGeneratorSpec<K,
V> - Returns:
- spec builder
-
with
Description copied from interface:MapGeneratorSpec
Adds 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 generate(field("someMap"), gen -> gen.map() .size(3) .with("key1", "value1") .with("key2", "value2")
- Specified by:
with
in interfaceMapGeneratorSpec<K,
V> - Parameters:
key
- to addvalue
- to add- Returns:
- spec builder
- See Also:
-
withKeys
Description copied from interface:MapGeneratorSpec
Adds 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:
withKeys
in interfaceMapGeneratorSpec<K,
V> - Parameters:
keys
- to add- Returns:
- spec builder
- See Also:
-
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:
- should be populated (for example, if it has
-