Package dev.orne.test.rnd.generators
Class AbstractPrimitiveGenerator<T>
java.lang.Object
dev.orne.test.rnd.AbstractGenerator
dev.orne.test.rnd.AbstractTypedGenerator<T>
dev.orne.test.rnd.generators.AbstractPrimitiveGenerator<T>
- Type Parameters:
T
- The primitive wrapper type
- All Implemented Interfaces:
Generator
,TypedGenerator<T>
- Direct Known Subclasses:
BooleanGenerator
,ByteGenerator
,CharacterGenerator
,DoubleGenerator
,FloatGenerator
,IntegerGenerator
,LongGenerator
,ShortGenerator
@API(status=STABLE,
since="0.1")
public abstract class AbstractPrimitiveGenerator<T>
extends AbstractTypedGenerator<T>
Abstract generator implementation for primitive types.
- Since:
- 0.1
- Version:
- 1.0, 2022-10
- Author:
- (w) Iker Hernaez
-
Field Summary
Fields inherited from class dev.orne.test.rnd.AbstractGenerator
DEFAULT_NULL_PROBABILITY
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Crates a new instance.protected
AbstractPrimitiveGenerator
(@NotNull Class<T> valueType) Crates a new instance. -
Method Summary
Modifier and TypeMethodDescription<R> R
nullableDefaultValue
(@NotNull Class<R> type) Returns the default value for the specified type allowingnull
values.boolean
randomNull
(@NotNull Class<?> type) Determines if the value must benull
based on the probability ofnull
values.boolean
Checks if values of the specified type can be generated by this instance.Methods inherited from class dev.orne.test.rnd.AbstractTypedGenerator
defaultValue, equals, getValueType, hashCode, nullableDefaultValue, nullableRandomValue, randomValue
Methods inherited from class dev.orne.test.rnd.AbstractGenerator
assertSupported, getNullProbability, nullableRandomValue, 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, nullableRandomValue
Methods inherited from interface dev.orne.test.rnd.TypedGenerator
defaultValue, randomValue
-
Constructor Details
-
AbstractPrimitiveGenerator
protected AbstractPrimitiveGenerator()Crates a new instance.Infers generated values type from the generic type arguments of this instance class. The class must extend
AbstractPrimitiveGenerator
specifying the generic types.Example:
class MyLongGenerator extends AbstractPrimitiveGenerator<Long> { ... }
-
AbstractPrimitiveGenerator
Crates a new instance.- Parameters:
valueType
- The type of generated values
-
-
Method Details
-
supports
Checks if values of the specified type can be generated by this instance.- Specified by:
supports
in interfaceGenerator
- Overrides:
supports
in classAbstractTypedGenerator<T>
- Parameters:
type
- The type to check.- Returns:
- If values of the specified type can be generated.
-
nullableDefaultValue
Returns the default value for the specified type allowingnull
values.This method should return
null
except for native types.- Specified by:
nullableDefaultValue
in interfaceGenerator
- Overrides:
nullableDefaultValue
in classAbstractGenerator
- Type Parameters:
R
- The requested value type.- Parameters:
type
- The requested value type.- Returns:
- The nullable default value for the specified type.
-
randomNull
Determines if the value must benull
based on the probability ofnull
values.Overriding classes can use the type parameter to detect non nullable types (like primitives).
- Overrides:
randomNull
in classAbstractGenerator
- Parameters:
type
- The requested value type- Returns:
- If the value must be
null
- See Also:
-