Class AbstractTargetedGenerator<T>
- Type Parameters:
T
- The type of generated values
- All Implemented Interfaces:
TargetedGenerator<T>
- Direct Known Subclasses:
ConstructorParameterTypeGenerator
,MethodParameterTypeGenerator
,MethodReturnTypeGenerator
,ParameterTypeGenerator
,PropertyTypeGenerator
TargetedGenerator
.- Since:
- 0.1
- Version:
- 1.0, 2022-11
- Author:
- (w) Iker Hernaez
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractTargetedGenerator
(@NotNull Class<T> valueType) Creates a new instance.protected
AbstractTargetedGenerator
(@NotNull Class<T> valueType, @NotNull Generator generator) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptiondefaultValue
(@NotNull Class<?>... groups) Returns the default value of the supported type.boolean
abstract Type
Returns the declared type of the target.protected @NotNull Generator
Returns the generator to use.getParameterSourceList
(@NotNull Class<?>... groups) Returns the generation parameter sources to be used.@NotNull Object[]
getParameterSources
(@NotNull Class<?>... groups) Returns the generation parameter sources to be used.protected abstract @NotNull Collection<Annotation>
getTargetConstraints
(@NotNull Class<?>... groups) Returns the constraints of the target for the specified validation groups.Returns the type of generated values.int
hashCode()
nullableDefaultValue
(@NotNull Class<?>... groups) Returns the default value for the specified type allowingnull
values.nullableRandomValue
(@NotNull Class<?>... groups) Returns a random value of the specified type.randomValue
(@NotNull Class<?>... groups) Returns a random value of the supported type.
-
Constructor Details
-
AbstractTargetedGenerator
Creates a new instance.- Parameters:
valueType
- The type of generated values.
-
AbstractTargetedGenerator
protected AbstractTargetedGenerator(@NotNull @NotNull Class<T> valueType, @NotNull @NotNull Generator generator) Creates a new instance.- Parameters:
valueType
- The type of generated values.generator
- The generator to use.
-
-
Method Details
-
getValueType
Returns the type of generated values.- Returns:
- The type of generated values.
-
getDeclaredType
Returns the declared type of the target.- Returns:
- The declared type of the target.
-
getGenerator
Returns the generator to use.- Returns:
- The generator to use.
-
defaultValue
Returns the default value of the supported type.If the generator for the type of the target is a
ParameterizableGenerator
extracts the parameters from the constraints of the target when applying the specified validation groups.- Specified by:
defaultValue
in interfaceTargetedGenerator<T>
- Parameters:
groups
- The validation groups to use when extracting the constraints of the target.- Returns:
- The default value.
-
nullableDefaultValue
Returns the default value for the specified type allowingnull
values.If the generator for the type of the target is a
ParameterizableGenerator
extracts the parameters from the constraints of the target when applying the specified validation groups.This method should return
null
except for native types or targets annotated withNotNull
.- Specified by:
nullableDefaultValue
in interfaceTargetedGenerator<T>
- Parameters:
groups
- The validation groups to use when extracting the constraints of the target.- Returns:
- The nullable default value for the specified type.
-
randomValue
Returns a random value of the supported type.If the generator for the type of the target is a
ParameterizableGenerator
extracts the parameters from the constraints of the target when applying the specified validation groups.- Specified by:
randomValue
in interfaceTargetedGenerator<T>
- Parameters:
groups
- The validation groups to use when extracting the constraints of the target- Returns:
- A random value.
-
nullableRandomValue
Returns a random value of the specified type.If the generator for the type of the target is a
ParameterizableGenerator
extracts the parameters from the constraints of the target when applying the specified validation groups.The returned value has a probability of be
null
except for native types or targets annotated withNotNull
. If notnull
behaves asrandomValue()
.- Specified by:
nullableRandomValue
in interfaceTargetedGenerator<T>
- Parameters:
groups
- The validation groups to use when extracting the constraints of the target.- Returns:
- A random nullable value.
- See Also:
-
getParameterSources
Returns the generation parameter sources to be used.The specified validation groups will be used to retrieve the constraints to use as sources.
- Specified by:
getParameterSources
in interfaceTargetedGenerator<T>
- Parameters:
groups
- The validation groups.- Returns:
- The generation parameter sources.
-
getParameterSourceList
@NotNull protected @NotNull List<Object> getParameterSourceList(@NotNull @NotNull Class<?>... groups) Returns the generation parameter sources to be used.The specified validation groups will be used to retrieve the constraints to use as sources.
- Parameters:
groups
- The validation groups .- Returns:
- The generation parameter sources
-
getTargetConstraints
@NotNull protected abstract @NotNull Collection<Annotation> getTargetConstraints(@NotNull @NotNull Class<?>... groups) Returns the constraints of the target for the specified validation groups.- Parameters:
groups
- The validation groups to use when extracting the constraints of the target- Returns:
- The constraints of the target
-
hashCode
public int hashCode() -
equals
-