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 intThe maximum generated array size.static final intThe 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> TdefaultValue(@NotNull Class<T> type) Returns the default value for the specified type.<T> TnullableRandomValue(@NotNull Class<T> type) Returns a random value of the specified type allowingnullvalues.protected @NotNull ObjectrandomArray(@NotNull Class<?> componentType, @NotNull Generator generator) Returns a random sized array of the specified component type.protected ObjectrandomNullablesArray(@NotNull Class<?> componentType, @NotNull Generator generator) Returns a random sized array of the specified component type allowingnullcomponent values.<T> TrandomValue(@NotNull Class<T> type) Returns a random value of the specified type.booleanChecks 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, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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 allowingnullvalues.The returned value has a probability of be
nullexcept for native types. If notnullbehaves asrandomValue().- Specified by:
nullableRandomValuein interfaceGenerator- Overrides:
nullableRandomValuein 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 allowingnullcomponent 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
-