T - type of property parameter to apply this generator's values topublic abstract class Generator<T> extends Object implements Gen<T>, Shrink<T>
| Modifier | Constructor and Description |
|---|---|
protected |
Generator(Class<T> type) |
protected |
Generator(List<Class<T>> types)
Used for generators of primitives and their wrappers.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addComponentGenerators(List<Generator<?>> newComponents)
Adds component generators to this generator.
|
boolean |
canGenerateForParametersOfTypes(List<org.javaruntype.type.TypeParameter<?>> typeParameters) |
boolean |
canRegisterAsType(Class<?> type)
Tells whether this generator is allowed to be used for property
parameters of the given type.
|
boolean |
canShrink(Object larger)
Tells whether this generator is allowed to participate in the
Shrink process for the given "larger" value. |
protected static boolean |
compatibleWithTypeParameter(org.javaruntype.type.TypeParameter<?> parameter,
Class<?> clazz) |
protected static List<Annotation> |
configurationAnnotationsOn(AnnotatedElement element)
Gives a list of the
GeneratorConfiguration annotations present
on the given program element. |
void |
configure(AnnotatedElement element) |
void |
configure(AnnotatedType annotatedType)
Configures this generator using annotations from a given annotated
type.
|
Generator<T> |
copy()
Used by the framework to make a copy of the receiver.
|
List<T> |
doShrink(SourceOfRandomness random,
T larger)
Gives some objects that are "smaller" than a given "larger"
object.
|
protected Generators |
gen() |
protected Generators |
gen(SourceOfRandomness random) |
boolean |
hasComponents()
This is intended for use only by junit-quickcheck itself, and not by
creators of custom generators.
|
BigDecimal |
magnitude(Object value)
Gives a hint to the shrinking process as to the magnitude of the given
value.
|
protected T |
narrow(Object wider)
Attempts to "narrow" the given object to the type this generator
produces.
|
int |
numberOfNeededComponents()
This is intended for use only by junit-quickcheck itself, and not by
creators of custom generators.
|
void |
provide(Generators provided)
Supplies the available generators to this one.
|
List<T> |
shrink(SourceOfRandomness random,
Object larger)
Gives some objects that are "smaller" than a given object.
|
List<Class<T>> |
types() |
protected Generator(Class<T> type)
type - class token for type of property parameter this generator is
applicable topublic List<Class<T>> types()
public boolean canRegisterAsType(Class<?> type)
type - type against which to test this generatortrue if the generator is allowed to participate in
generating values for property parameters of typepublic final List<T> shrink(SourceOfRandomness random, Object larger)
Generators first ensure that they can participate in shrinking the given value, and if so, they produce shrinks.
public boolean canShrink(Object larger)
Tells whether this generator is allowed to participate in the
Shrink process for the given "larger" value.
Unless overridden, the only criterion for whether a generator is allowed to participate in shrinking a value is if the value can be safely cast to the type of values the generator produces.
larger - the "larger" valuepublic List<T> doShrink(SourceOfRandomness random, T larger)
Gives some objects that are "smaller" than a given "larger" object.
Unless overridden, a generator will produce an empty list of "smaller" values.
random - source of randomness to use in shrinking, if desiredlarger - the larger objectpublic BigDecimal magnitude(Object value)
Gives a hint to the shrinking process as to the magnitude of the given value. The shrinking process will prefer trying values of greater magnitude before values of lesser magnitude. If not overridden, this implementation returns "one".
Note to generator writers: Do not worry about normalizing a magnitude to a positive value; the shrinking mechanism will take care of it.
value - the value to assessnarrow(Object)protected final T narrow(Object wider)
Attempts to "narrow" the given object to the type this generator produces.
This is intended for use only by junit-quickcheck itself, and not by creators of custom generators.
wider - target of the narrowingClassCastException - if the narrowing cannot be performedpublic boolean hasComponents()
This is intended for use only by junit-quickcheck itself, and not by creators of custom generators.
addComponentGenerators(java.util.List)public int numberOfNeededComponents()
This is intended for use only by junit-quickcheck itself, and not by creators of custom generators.
addComponentGenerators(java.util.List)public void addComponentGenerators(List<Generator<?>> newComponents)
Adds component generators to this generator.
Some generators need component generators to create proper values. For example, list generators require a single component generator in order to generate elements that have the type of the list parameter's type argument.
This is intended for use only by junit-quickcheck itself, and not by creators of custom generators.
newComponents - component generators to addpublic boolean canGenerateForParametersOfTypes(List<org.javaruntype.type.TypeParameter<?>> typeParameters)
typeParameters - a list of generic type parameterspublic void configure(AnnotatedType annotatedType)
Configures this generator using annotations from a given annotated type.
This method considers only annotations that are themselves marked
with GeneratorConfiguration.
By default, the generator will configure itself using this procedure:
public method on the generator named
configure, that accepts a single parameter of the
annotation typeconfigure method reflectively, passing the
annotation as the argumentannotatedType - a type usageGeneratorConfigurationException - if the generator does not
"understand" one of the generation configuration annotations on
the annotated typepublic void configure(AnnotatedElement element)
element - an annotated program elementpublic void provide(Generators provided)
Supplies the available generators to this one.
This is intended for use only by junit-quickcheck itself, and not by creators of custom generators.
provided - repository of available generatorspublic Generator<T> copy()
protected static boolean compatibleWithTypeParameter(org.javaruntype.type.TypeParameter<?> parameter,
Class<?> clazz)
parameter - a generic type parameterclazz - a typecanGenerateForParametersOfTypes(List)protected Generators gen()
protected Generators gen(SourceOfRandomness random)
random - a source of randomness used when locating other
generatorsprotected static List<Annotation> configurationAnnotationsOn(AnnotatedElement element)
GeneratorConfiguration annotations present
on the given program element.element - an annotated program elementCopyright © 2019. All rights reserved.