Package org.instancio.generator.specs
Interface MapGeneratorSpec<K,V>
- Type Parameters:
K
- key typeV
- value type
- All Superinterfaces:
GeneratorSpec<Map<K,
,V>> NullableGeneratorSpec<Map<K,
,V>> SubtypeGeneratorSpec<Map<K,
V>>
- All Known Implementing Classes:
MapGenerator
,MapGeneratorSpecImpl
public interface MapGeneratorSpec<K,V>
extends NullableGeneratorSpec<Map<K,V>>, SubtypeGeneratorSpec<Map<K,V>>
Generator spec for maps.
-
Method Summary
Modifier and TypeMethodDescriptionmaxSize
(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.Adds given keys to the map in the order they are provided.
-
Method Details
-
size
Size of map to generate.- Parameters:
size
- of map- Returns:
- spec builder
-
minSize
Minimum size of map to generate.- Parameters:
size
- minimum size (inclusive)- Returns:
- spec builder
-
maxSize
Maximum size of map to generate.- Parameters:
size
- maximum size (inclusive)- Returns:
- spec builder
-
nullable
MapGeneratorSpec<K,V> nullable()Indicates thatnull
value can be generated for the map.- Specified by:
nullable
in interfaceNullableGeneratorSpec<K>
- Returns:
- spec builder
-
nullableKeys
MapGeneratorSpec<K,V> nullableKeys()Indicates thatnull
values can be generated for map keys.- Returns:
- spec builder
-
nullableValues
MapGeneratorSpec<K,V> nullableValues()Indicates thatnull
values can be generated for map values.- Returns:
- spec builder
-
subtype
Specifies the type of map that should be generated.- Specified by:
subtype
in interfaceSubtypeGeneratorSpec<K>
- Parameters:
type
- of collection to generate- Returns:
- spec builder
- Since:
- 1.4.0
-
with
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 (3 random + 2 custom entries) generate(field("someMap"), gen -> gen.map() .size(3) .with("key1", "value1") .with("key2", "value2")
- Parameters:
key
- to addvalue
- to add- Returns:
- spec builder
- Since:
- 2.0.0
- See Also:
-
withKeys
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")
- Parameters:
keys
- to add- Returns:
- spec builder
- Since:
- 2.0.0
- See Also:
-