Package dev.orne.test.rnd.generators
Class SetGenerator
java.lang.Object
dev.orne.test.rnd.AbstractGenerator
dev.orne.test.rnd.params.AbstractParameterizableGenerator<P>
dev.orne.test.rnd.params.AbstractTypedParameterizableGenerator<Set<?>,CollectionGenerationParameters>
dev.orne.test.rnd.generators.SetGenerator
- All Implemented Interfaces:
Generator,ParameterizableGenerator,TypedParameterizableGenerator<Set<?>>,TypedGenerator<Set<?>>
@API(status=STABLE,
since="0.1")
@Priority(-2000)
public class SetGenerator
extends AbstractTypedParameterizableGenerator<Set<?>,CollectionGenerationParameters>
Generator of
Set 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 intThe maximum generated set size.static final intThe minimum generated set size.Fields inherited from class dev.orne.test.rnd.AbstractGenerator
DEFAULT_NULL_PROBABILITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull Set<?>defaultValue(@NotNull CollectionGenerationParameters parameters) Returns the default value of the supported type for the specified parameters.Set<?>nullableRandomValue(@NotNull CollectionGenerationParameters parameters) Returns a random value of the supported type for the specified parameters allowingnullvalues.<T> TnullableRandomValue(@NotNull Class<T> type, @NotNull CollectionGenerationParameters parameters) Returns a random value of the specified type and parameters.protected Set<?>randomNullablesSet(@NotNull CollectionGenerationParameters parameters) Returns a random sized set of the specified component type allowingnullcomponent values.protected @NotNull Set<?>randomSet(@NotNull CollectionGenerationParameters parameters) Returns a random sized set of the specified component type.protected intrandomSize(@NotNull CollectionGenerationParameters parameters) Returns a random set size.@NotNull Set<?>randomValue(@NotNull CollectionGenerationParameters parameters) Returns a random value of the supported type for the specified parameters.protected voidvalidateParameters(@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, supportsMethods inherited from class dev.orne.test.rnd.params.AbstractParameterizableGenerator
createEmptyParams, createParams, defaultValue, defaultValue, getExtractor, getParametersType, nullableDefaultValue, nullableDefaultValue, nullableDefaultValue, nullableRandomValue, nullableRandomValue, randomValue, randomValueMethods inherited from class dev.orne.test.rnd.AbstractGenerator
assertSupported, getNullProbability, randomNull, setNullProbability, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface dev.orne.test.rnd.Generator
asParameterizable, defaultValue, getPriority, nullableDefaultValue, nullableRandomValue, randomValueMethods 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 set size.- See Also:
-
MAX_SIZE
public static final int MAX_SIZEThe maximum generated set size.- See Also:
-
-
Constructor Details
-
SetGenerator
public SetGenerator()Creates a new instance.
-
-
Method Details
-
defaultValue
@NotNull public @NotNull Set<?> defaultValue(@NotNull @NotNull CollectionGenerationParameters parameters) Returns the default value of the supported type for the specified parameters.- Specified by:
defaultValuein classAbstractTypedParameterizableGenerator<Set<?>,CollectionGenerationParameters> - Parameters:
parameters- The generation parameters- Returns:
- The default value.
-
randomValue
@NotNull public @NotNull Set<?> randomValue(@NotNull @NotNull CollectionGenerationParameters parameters) Returns a random value of the supported type for the specified parameters.- Specified by:
randomValuein classAbstractTypedParameterizableGenerator<Set<?>,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
nullexcept for native types when noNotNullconstraint is present. If notnullbehaves asrandomValue().- Overrides:
nullableRandomValuein 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 allowingnullvalues.The returned value has a probability of be
nullexcept for native types. If notnullbehaves asrandomValue().- Overrides:
nullableRandomValuein classAbstractTypedParameterizableGenerator<Set<?>,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.
-
randomSet
@NotNull protected @NotNull Set<?> randomSet(@NotNull @NotNull CollectionGenerationParameters parameters) Returns a random sized set of the specified component type.- Parameters:
parameters- The generation parameters.- Returns:
- A random set for the specified component type.
- Throws:
GenerationException- If an error occurs generating the value
-
randomNullablesSet
Returns a random sized set of the specified component type allowingnullcomponent values.- Parameters:
parameters- The generation parameters.- Returns:
- A random set of the specified component type.
- Throws:
GenerationException- If an error occurs generating the value
-
randomSize
Returns a random set size.- Parameters:
parameters- The generation parameters.- Returns:
- The set size.
-