Package dev.orne.test.rnd.generators
Class ListGenerator
java.lang.Object
dev.orne.test.rnd.AbstractGenerator
dev.orne.test.rnd.params.AbstractParameterizableGenerator<P>
dev.orne.test.rnd.params.AbstractTypedParameterizableGenerator<List<?>,CollectionGenerationParameters>
dev.orne.test.rnd.generators.ListGenerator
- All Implemented Interfaces:
Generator
,ParameterizableGenerator
,TypedParameterizableGenerator<List<?>>
,TypedGenerator<List<?>>
@API(status=STABLE,
since="0.1")
@Priority(-2000)
public class ListGenerator
extends AbstractTypedParameterizableGenerator<List<?>,CollectionGenerationParameters>
Generator of
List
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 list size.static final int
The minimum generated list size.Fields inherited from class dev.orne.test.rnd.AbstractGenerator
DEFAULT_NULL_PROBABILITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull List<?>
defaultValue
(@NotNull CollectionGenerationParameters parameters) Returns the default value of the supported type for the specified parameters.List<?>
nullableRandomValue
(@NotNull CollectionGenerationParameters parameters) Returns a random value of the supported type for the specified parameters allowingnull
values.<T> T
nullableRandomValue
(@NotNull Class<T> type, @NotNull CollectionGenerationParameters parameters) Returns a random value of the specified type and parameters.protected @NotNull List<?>
randomList
(@NotNull CollectionGenerationParameters parameters) Returns a random sized list of the specified component type.protected List<?>
randomNullablesList
(@NotNull CollectionGenerationParameters parameters) Returns a random sized list of the specified component type allowingnull
component values.protected int
randomSize
(@NotNull CollectionGenerationParameters parameters) Returns a random list size.@NotNull List<?>
randomValue
(@NotNull CollectionGenerationParameters parameters) Returns a random value of the supported type for the specified parameters.boolean
Checks if values of the specified type can be generated by this instance.protected void
validateParameters
(@NotNull CollectionGenerationParameters 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
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 list size.- See Also:
-
MAX_SIZE
public static final int MAX_SIZEThe maximum generated list size.- See Also:
-
-
Constructor Details
-
ListGenerator
public ListGenerator()Creates a new instance.
-
-
Method Details
-
supports
Checks if values of the specified type can be generated by this instance.- Specified by:
supports
in interfaceGenerator
- Overrides:
supports
in classAbstractTypedParameterizableGenerator<List<?>,
CollectionGenerationParameters> - Parameters:
type
- The type to check.- Returns:
- If values of the specified type can be generated.
-
defaultValue
@NotNull public @NotNull List<?> defaultValue(@NotNull @NotNull CollectionGenerationParameters parameters) Returns the default value of the supported type for the specified parameters.- Specified by:
defaultValue
in classAbstractTypedParameterizableGenerator<List<?>,
CollectionGenerationParameters> - Parameters:
parameters
- The generation parameters- Returns:
- The default value.
-
randomValue
@NotNull public @NotNull List<?> randomValue(@NotNull @NotNull CollectionGenerationParameters parameters) Returns a random value of the supported type for the specified parameters.- Specified by:
randomValue
in classAbstractTypedParameterizableGenerator<List<?>,
CollectionGenerationParameters> - Parameters:
parameters
- The generation parameters- Returns:
- A random value.
-
nullableRandomValue
public <T> T nullableRandomValue(@NotNull @NotNull Class<T> type, @NotNull @NotNull CollectionGenerationParameters 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<CollectionGenerationParameters>
- 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<List<?>,
CollectionGenerationParameters> - 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.
-
randomList
@NotNull protected @NotNull List<?> randomList(@NotNull @NotNull CollectionGenerationParameters parameters) Returns a random sized list of the specified component type.- Parameters:
parameters
- The generation parameters.- Returns:
- A random list for the specified component type.
- Throws:
GenerationException
- If an error occurs generating the value
-
randomNullablesList
Returns a random sized list of the specified component type allowingnull
component values.- Parameters:
parameters
- The generation parameters.- Returns:
- A random list of the specified component type.
- Throws:
GenerationException
- If an error occurs generating the value
-
randomSize
Returns a random list size.- Parameters:
parameters
- The generation parameters.- Returns:
- The list size.
-