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 floatThe default probability ofnullvalues. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidassertSupported(@NotNull Class<?> type) Verifies that the specified type is supported by this instance.boolean@javax.validation.constraints.Min(0L),@javax.validation.constraints.Max(1L) floatReturns the probability ofnullvalue innullableRandomValue(Class).inthashCode()<T> TnullableDefaultValue(@NotNull Class<T> type) Returns the default value for the specified type allowingnullvalues.<T> TnullableRandomValue(@NotNull Class<T> type) Returns a random value of the specified type allowingnullvalues.booleanrandomNull(@NotNull Class<?> type) Determines if the value must benullbased on the probability ofnullvalues.voidsetNullProbability(@javax.validation.constraints.Min(0L),@javax.validation.constraints.Max(1L) float prob) Sets the probability ofnullvalue innullableRandomValue(Class).toString()Methods 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, randomValue, supports
-
Field Details
-
DEFAULT_NULL_PROBABILITY
public static final float DEFAULT_NULL_PROBABILITYThe default probability ofnullvalues.- 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 anIllegalArgumentExceptionexception 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 allowingnullvalues.This method should return
nullexcept for native types.- Specified by:
nullableDefaultValuein 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 allowingnullvalues.The returned value has a probability of be
nullexcept for native types. If notnullbehaves asrandomValue().- Specified by:
nullableRandomValuein 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 ofnullvalue innullableRandomValue(Class).- Returns:
- The probability of
nullvalues.
-
setNullProbability
public void setNullProbability(@Min(0L) @Max(1L) @javax.validation.constraints.Min(0L),@javax.validation.constraints.Max(1L) float prob) Sets the probability ofnullvalue innullableRandomValue(Class).- Parameters:
prob- The probability ofnullvalues.
-
randomNull
Determines if the value must benullbased on the probability ofnullvalues.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
-