Package dev.orne.test.rnd.generators
Class MapGenerator
java.lang.Object
dev.orne.test.rnd.AbstractGenerator
dev.orne.test.rnd.params.AbstractParameterizableGenerator<P>
dev.orne.test.rnd.params.AbstractTypedParameterizableGenerator<Map<?,?>,MapGenerationParameters>
dev.orne.test.rnd.generators.MapGenerator
- All Implemented Interfaces:
Generator
,ParameterizableGenerator
,TypedParameterizableGenerator<Map<?,
,?>> TypedGenerator<Map<?,
?>>
@API(status=STABLE,
since="0.1")
@Priority(-2000)
public class MapGenerator
extends AbstractTypedParameterizableGenerator<Map<?,?>,MapGenerationParameters>
Generator of
Map
values.
Requires supported component type generation in Generators
.- Since:
- 0.1
- Version:
- 1.0, 2022-12
- Author:
- (w) Iker Hernaez
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The maximum generated array size.static final int
The minimum generated array size.Fields inherited from class dev.orne.test.rnd.AbstractGenerator
DEFAULT_NULL_PROBABILITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull Map<?,
?> defaultValue
(@NotNull MapGenerationParameters parameters) Returns the default value of the supported type for the specified parameters.Map<?,
?> nullableRandomValue
(@NotNull MapGenerationParameters parameters) Returns a random value of the supported type for the specified parameters allowingnull
values.<T> T
nullableRandomValue
(@NotNull Class<T> type, @NotNull MapGenerationParameters parameters) Returns a random value of the specified type and parameters.protected @NotNull Map<?,
?> randomMap
(@NotNull MapGenerationParameters parameters) Returns a random sized map of the specified keys and values types.protected Map<?,
?> randomNullablesMap
(@NotNull MapGenerationParameters parameters) Returns a random sized map of the specified keys and values types allowingnull
values.protected int
randomSize
(@NotNull MapGenerationParameters parameters) Returns a random map size.@NotNull Map<?,
?> randomValue
(@NotNull MapGenerationParameters parameters) Returns a random value of the supported type for the specified parameters.protected void
validateParameters
(@NotNull MapGenerationParameters parameters) Validates that the parameters contain enough information to generate the values.Methods inherited from class dev.orne.test.rnd.params.AbstractTypedParameterizableGenerator
defaultValue, defaultValue, defaultValue, equals, getValueType, hashCode, nullableDefaultValue, nullableDefaultValue, nullableDefaultValue, nullableRandomValue, nullableRandomValue, randomValue, randomValue, randomValue, supports
Methods inherited from class dev.orne.test.rnd.params.AbstractParameterizableGenerator
createEmptyParams, createParams, defaultValue, defaultValue, getExtractor, getParametersType, nullableDefaultValue, nullableDefaultValue, nullableDefaultValue, nullableRandomValue, nullableRandomValue, randomValue, randomValue
Methods inherited from class dev.orne.test.rnd.AbstractGenerator
assertSupported, getNullProbability, randomNull, setNullProbability, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface dev.orne.test.rnd.Generator
asParameterizable, defaultValue, getPriority, nullableDefaultValue, nullableRandomValue, randomValue
Methods inherited from interface dev.orne.test.rnd.params.ParameterizableGenerator
defaultValue, nullableDefaultValue, nullableRandomValue, randomValue
-
Field Details
-
MIN_SIZE
public static final int MIN_SIZEThe minimum generated array size.- See Also:
-
MAX_SIZE
public static final int MAX_SIZEThe maximum generated array size.- See Also:
-
-
Constructor Details
-
MapGenerator
public MapGenerator()Creates a new instance.
-
-
Method Details
-
defaultValue
@NotNull public @NotNull Map<?,?> defaultValue(@NotNull @NotNull MapGenerationParameters parameters) Returns the default value of the supported type for the specified parameters.- Specified by:
defaultValue
in classAbstractTypedParameterizableGenerator<Map<?,
?>, MapGenerationParameters> - Parameters:
parameters
- The generation parameters- Returns:
- The default value.
-
randomValue
Returns a random value of the supported type for the specified parameters.- Specified by:
randomValue
in classAbstractTypedParameterizableGenerator<Map<?,
?>, MapGenerationParameters> - Parameters:
parameters
- The generation parameters- Returns:
- A random value.
-
nullableRandomValue
public <T> T nullableRandomValue(@NotNull @NotNull Class<T> type, @NotNull @NotNull MapGenerationParameters parameters) Returns a random value of the specified type and parameters.The returned value has a probability of be
null
except for native types when noNotNull
constraint is present. If notnull
behaves asrandomValue()
.- Overrides:
nullableRandomValue
in classAbstractParameterizableGenerator<MapGenerationParameters>
- Type Parameters:
T
- The requested value type.- Parameters:
type
- The requested value type.parameters
- The generation parameters- Returns:
- A random nullable value for the specified type.
- See Also:
-
nullableRandomValue
Returns a random value of the supported type for the specified parameters allowingnull
values.The returned value has a probability of be
null
except for native types. If notnull
behaves asrandomValue()
.- Overrides:
nullableRandomValue
in classAbstractTypedParameterizableGenerator<Map<?,
?>, MapGenerationParameters> - Parameters:
parameters
- The generation parameters- Returns:
- A random nullable value.
- See Also:
-
validateParameters
Validates that the parameters contain enough information to generate the values.- Parameters:
parameters
- The generation parameters.
-
randomMap
@NotNull protected @NotNull Map<?,?> randomMap(@NotNull @NotNull MapGenerationParameters parameters) Returns a random sized map of the specified keys and values types.- Parameters:
parameters
- The generation parameters.- Returns:
- A random map for the specified keys and values types.
- Throws:
GenerationException
- If an error occurs generating the value
-
randomNullablesMap
Returns a random sized map of the specified keys and values types allowingnull
values.- Parameters:
parameters
- The generation parameters.- Returns:
- A random map of the specified keys and values types.
- Throws:
GenerationException
- If an error occurs generating the value
-
randomSize
Returns a random map size.- Parameters:
parameters
- The generation parameters.- Returns:
- The map size.
-