Package dev.orne.test.rnd.generators
Class ArrayGenerator
java.lang.Object
dev.orne.test.rnd.AbstractGenerator
dev.orne.test.rnd.generators.ArrayGenerator
- All Implemented Interfaces:
Generator
@API(status=STABLE,
since="0.1")
@Priority(-2000)
public class ArrayGenerator
extends AbstractGenerator
Generator of array values.
Requires supported component type generation in
Generators
.- Since:
- 0.1
- Version:
- 1.0, 2022-11
- 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<T> T
defaultValue
(@NotNull Class<T> type) Returns the default value for the specified type.<T> T
nullableRandomValue
(@NotNull Class<T> type) Returns a random value of the specified type allowingnull
values.protected @NotNull Object
randomArray
(@NotNull Class<?> componentType, @NotNull Generator generator) Returns a random sized array of the specified component type.protected Object
randomNullablesArray
(@NotNull Class<?> componentType, @NotNull Generator generator) Returns a random sized array of the specified component type allowingnull
component values.<T> T
randomValue
(@NotNull Class<T> type) Returns a random value of the specified type.boolean
Checks if values of the specified type can be generated by this instance.Methods inherited from class dev.orne.test.rnd.AbstractGenerator
assertSupported, equals, getNullProbability, hashCode, nullableDefaultValue, 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, getPriority
-
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
-
ArrayGenerator
public ArrayGenerator()Creates a new instance.
-
-
Method Details
-
supports
Checks if values of the specified type can be generated by this instance.- Parameters:
type
- The type to check.- Returns:
- If values of the specified type can be generated.
-
defaultValue
Returns the default value for the specified type.- Type Parameters:
T
- The requested value type.- Parameters:
type
- The requested value type.- Returns:
- The default value for the specified type.
-
randomValue
Returns a random value of the specified type.- Type Parameters:
T
- The requested value type.- Parameters:
type
- The requested value type.- Returns:
- A random value for the specified type.
-
randomArray
@NotNull protected @NotNull Object randomArray(@NotNull @NotNull Class<?> componentType, @NotNull @NotNull Generator generator) Returns a random sized array of the specified component type.- Parameters:
componentType
- The requested component type.generator
- The generator to use to generate the array values.- Returns:
- A random array for the specified component type.
- Throws:
GenerationException
- If an error occurs generating the value
-
nullableRandomValue
Returns a random value of the specified type allowingnull
values.The returned value has a probability of be
null
except for native types. If notnull
behaves asrandomValue()
.- Specified by:
nullableRandomValue
in interfaceGenerator
- Overrides:
nullableRandomValue
in classAbstractGenerator
- Type Parameters:
T
- The requested value type.- Parameters:
type
- The requested value type.- Returns:
- A random nullable value for the specified type.
- See Also:
-
randomNullablesArray
protected Object randomNullablesArray(@NotNull @NotNull Class<?> componentType, @NotNull @NotNull Generator generator) Returns a random sized array of the specified component type allowingnull
component values.- Parameters:
componentType
- The requested component type.generator
- The generator to use for component values.- Returns:
- A random array of the specified component type.
- Throws:
GenerationException
- If an error occurs generating the value
-