Package dev.orne.test.rnd
Class AbstractGenerator
java.lang.Object
dev.orne.test.rnd.AbstractGenerator
- All Implemented Interfaces:
Generator
- Direct Known Subclasses:
AbstractParameterizableGenerator
,AbstractTypedGenerator
,ArrayGenerator
,EnumGenerator
@API(status=STABLE,
since="0.1")
public abstract class AbstractGenerator
extends Object
implements Generator
Abstract basic implementation of
Generator
.
Provides basic implementations for common methods.- Since:
- 0.1
- Version:
- 1.0, 2021-03
- Author:
- (w) Iker Hernaez
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final float
The default probability ofnull
values. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
assertSupported
(@NotNull Class<?> type) Verifies that the specified type is supported by this instance.boolean
@javax.validation.constraints.Min(0L),@javax.validation.constraints.Max(1L) float
Returns the probability ofnull
value innullableRandomValue(Class)
.int
hashCode()
<T> T
nullableDefaultValue
(@NotNull Class<T> type) Returns the default value for the specified type allowingnull
values.<T> T
nullableRandomValue
(@NotNull Class<T> type) Returns a random value of the specified type allowingnull
values.boolean
randomNull
(@NotNull Class<?> type) Determines if the value must benull
based on the probability ofnull
values.void
setNullProbability
(@javax.validation.constraints.Min(0L),@javax.validation.constraints.Max(1L) float prob) Sets the probability ofnull
value innullableRandomValue(Class)
.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, randomValue, supports
-
Field Details
-
DEFAULT_NULL_PROBABILITY
public static final float DEFAULT_NULL_PROBABILITYThe default probability ofnull
values.- See Also:
-
-
Constructor Details
-
AbstractGenerator
protected AbstractGenerator()Creates a new instance.
-
-
Method Details
-
assertSupported
Verifies that the specified type is supported by this instance. If test fails throws anIllegalArgumentException
exception as documented inGenerator.defaultValue(Class)
,nullableDefaultValue(Class)
,Generator.randomValue(Class)
andnullableRandomValue(Class)
.- Parameters:
type
- The requested value type.- Throws:
UnsupportedValueTypeException
- If the specified type is not supported.
-
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
- Type Parameters:
T
- The requested value type.- Parameters:
type
- The requested value type.- Returns:
- The nullable default value for the specified type.
-
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
- Type Parameters:
T
- The requested value type.- Parameters:
type
- The requested value type.- Returns:
- A random nullable value for the specified type.
- See Also:
-
getNullProbability
@Min(0L) @Max(1L) public @javax.validation.constraints.Min(0L),@javax.validation.constraints.Max(1L) float getNullProbability()Returns the probability ofnull
value innullableRandomValue(Class)
.- Returns:
- The probability of
null
values.
-
setNullProbability
public void setNullProbability(@Min(0L) @Max(1L) @javax.validation.constraints.Min(0L),@javax.validation.constraints.Max(1L) float prob) Sets the probability ofnull
value innullableRandomValue(Class)
.- Parameters:
prob
- The probability ofnull
values.
-
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).
- Parameters:
type
- The requested value type- Returns:
- If the value must be
null
- See Also:
-
hashCode
public int hashCode() -
equals
-
toString
-