Class MapGenerator<T extends Map>
- Type Parameters:
T- the type of map generated
- Direct Known Subclasses:
HashMapGenerator,HashtableGenerator,LinkedHashMapGenerator
Base class for generators of Maps.
The generated map has a number of entries limited by
GenerationStatus.size(), or else by the attributes of a Size
marking. The individual keys and values will have types corresponding to the
property parameter's type arguments.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidTells this generator to add entries whose keys are distinct from each other.voidTells this generator to add key-value pairs to the generated map a number of times within a specified minimum and/or maximum, inclusive, chosen with uniform distribution.private TdoShrink(SourceOfRandomness random, T larger) Gives some objects that are "smaller" than a given "larger" object.protected final Tempty()entryShrinker(Shrink<Object> keyShrinker, Shrink<Object> valueShrinker) generate(SourceOfRandomness random, GenerationStatus status) Generates a value, possibly influenced by a source of randomness and metadata about the generation.private booleaninSizeRange(T target) private static booleanisKeyDistinct(List<Map.Entry<?, ?>> entries) Gives a hint to the shrinking process as to the magnitude of the given value.intThis is intended for use only by junit-quickcheck itself, and not by creators of custom generators.protected booleanprivate intsize(SourceOfRandomness random, GenerationStatus status) Methods inherited from class com.pholser.junit.quickcheck.generator.ComponentizedGenerator
addComponentGenerators, canGenerateForParametersOfTypes, canRegisterAsType, componentGenerators, configure, hasComponents, provideMethods inherited from class com.pholser.junit.quickcheck.generator.Generator
canShrink, compatibleWithTypeParameter, configurationAnnotationsOn, configure, copy, gen, gen, narrow, shrink, types
-
Field Details
-
sizeRange
-
distinct
private boolean distinct
-
-
Constructor Details
-
MapGenerator
-
-
Method Details
-
configure
Tells this generator to add key-value pairs to the generated map a number of times within a specified minimum and/or maximum, inclusive, chosen with uniform distribution.
Note that maps disallow duplicate keys, so the number of pairs added may not be equal to the map's
Map.size().- Parameters:
size- annotation that gives the size constraints
-
configure
Tells this generator to add entries whose keys are distinct from each other.- Parameters:
distinct- Keys of generated entries will be distinct if this param is not null
-
generate
Description copied from interface:GenGenerates a value, possibly influenced by a source of randomness and metadata about the generation.- Parameters:
random- source of randomness to be used when generating the valuestatus- an object that can be used to influence the generated value. For example, generating lists can use thesizemethod to generate lists with a given number of elements.- Returns:
- the generated value
-
doShrink
Description copied from class:GeneratorGives some objects that are "smaller" than a given "larger" object.
Unless overridden, a generator will produce an empty list of "smaller" values.
- Overrides:
doShrinkin classGenerator<T extends Map>- Parameters:
random- source of randomness to use in shrinking, if desiredlarger- the larger object- Returns:
- objects that are "smaller" than the larger object. Smaller objects should be provided before bigger objects to make shrinking process faster.
-
numberOfNeededComponents
public int numberOfNeededComponents()Description copied from class:GeneratorThis is intended for use only by junit-quickcheck itself, and not by creators of custom generators.
- Overrides:
numberOfNeededComponentsin classGenerator<T extends Map>- Returns:
- how many component generators this generator needs
- See Also:
-
magnitude
Description copied from class:GeneratorGives 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.
-
empty
-
okToAdd
-
inSizeRange
-
size
-
removals
-
convert
-
entryShrinker
-
isKeyDistinct
-