Interface Gen<T>
- Type Parameters:
T- type of values generated
- All Known Implementing Classes:
AbstractStringGenerator,ArrayGenerator,ArrayListGenerator,BiFunctionGenerator,BigDecimalGenerator,BigIntegerGenerator,BinaryOperatorGenerator,BiPredicateGenerator,BitSetGenerator,BooleanGenerator,ByteGenerator,CallableGenerator,CharacterGenerator,CharsetGenerator,ClockGenerator,CollectionGenerator,ComponentizedGenerator,CompositeGenerator,Ctor,DateGenerator,DecimalGenerator,DoubleFunctionGenerator,DoubleGenerator,DurationGenerator,Encoded,EnumGenerator,ExhaustiveDomainGenerator,Fields,FloatGenerator,FunctionGenerator,FunctionGenerator,Generator,GuaranteeValuesGenerator,HashMapGenerator,HashSetGenerator,HashtableGenerator,InstantGenerator,IntegerGenerator,IntegralGenerator,IntFunctionGenerator,LambdaGenerator,LinkedHashMapGenerator,LinkedHashSetGenerator,LinkedListGenerator,ListGenerator,LocalDateGenerator,LocalDateTimeGenerator,LocaleGenerator,LocalTimeGenerator,LongFunctionGenerator,LongGenerator,MapGenerator,MarkerInterfaceGenerator,MonthDayGenerator,NullableGenerator,OffsetDateTimeGenerator,OffsetTimeGenerator,OptionalDoubleGenerator,OptionalGenerator,OptionalGenerator,OptionalIntGenerator,OptionalLongGenerator,PeriodGenerator,PredicateGenerator,PredicateGenerator,PropertiesGenerator,RFC4122.AbstractUUIDGenerator,RFC4122.NameBasedUUIDGenerator,RFC4122.Version3,RFC4122.Version4,RFC4122.Version5,SamplingDomainGenerator,SetGenerator,ShortGenerator,StackGenerator,StringGenerator,SupplierGenerator,SupplierGenerator,TimeZoneGenerator,ToDoubleBiFunctionGenerator,ToDoubleFunctionGenerator,ToIntBiFunctionGenerator,ToIntFunctionGenerator,ToLongBiFunctionGenerator,ToLongFunctionGenerator,UnaryOperatorGenerator,VectorGenerator,VoidGenerator,YearGenerator,YearMonthGenerator,ZilchGenerator,ZonedDateTimeGenerator,ZoneIdGenerator,ZoneOffsetGenerator
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Represents a strategy for generating random values.
-
Method Summary
Modifier and TypeMethodDescriptiondefault T_gen(SourceOfRandomness random, GenerationStatus status) Deprecated.Gives a generation strategy that produces a random value by having this strategy produce random values until one satisfies the given condition, then using that value as the result.filterOptional(Predicate<? super T> condition) default <U> Gen<U>Gives a generation strategy that produces a random value by having this strategy produce a random value, then applying the given function to that value, and asking the result to produce a value.Helper for making a weighted generator indicator forfrequency(Pair, Pair[]).static <U> Gen<U>Gives a generation strategy that produces a random value by choosing one of the given generators at random with probability in proportion to their given weights, and having it generate a value.generate(SourceOfRandomness random, GenerationStatus status) Generates a value, possibly influenced by a source of randomness and metadata about the generation.default <U> Gen<U>Gives a generation strategy that produces a random value by having this strategy produce a random value, then applying the given function to that value, and returning the result.static <U> Gen<U>Gives a generation strategy that produces a random value by choosing one of the given generators at random with (approximately) equal probability, and having it generate a value.static <U> Gen<U>oneOf(U first, U... rest) Gives a generation strategy that produces a random value by choosing one of the given values at random with (approximately) equal probability.static <U> Gen<U>pure(U constant) Gives a generation strategy that produces the given value, always.times(int times)
-
Method Details
-
generate
Generates 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
-
map
Gives a generation strategy that produces a random value by having this strategy produce a random value, then applying the given function to that value, and returning the result.- Type Parameters:
U- type of values produced by the mapped generation strategy- Parameters:
mapper- function that converts receiver's random values to result's values- Returns:
- a new generation strategy
-
flatMap
Gives a generation strategy that produces a random value by having this strategy produce a random value, then applying the given function to that value, and asking the result to produce a value.- Type Parameters:
U- type of values produced by the mapped generation strategy- Parameters:
mapper- function that converts receiver's random values to another kind of generation strategy- Returns:
- a new generation strategy
-
filter
Gives a generation strategy that produces a random value by having this strategy produce random values until one satisfies the given condition, then using that value as the result.- Parameters:
condition- a condition the generated value is to meet- Returns:
- a new generation strategy
-
filterOptional
Gives a generation strategy that produces a random value by having this strategy produce a random value and wrapping it in an
Optional; if the value meets the given condition, the wrapping optional will be present.If the value meets the condition but is
null, the wrapping optional will not be considered present.- Parameters:
condition- a condition the generated value is to meet- Returns:
- a new generation strategy
-
times
-
pure
Gives a generation strategy that produces the given value, always.- Type Parameters:
U- type of values produced by the resulting strategy- Parameters:
constant- the value to be returned by the resulting strategy- Returns:
- a new generation strategy
-
oneOf
Gives a generation strategy that produces a random value by choosing one of the given values at random with (approximately) equal probability.- Type Parameters:
U- type of values produced by the resulting strategy- Parameters:
first- first possible choicerest- the other possible choices- Returns:
- a new generation strategy
-
oneOf
Gives a generation strategy that produces a random value by choosing one of the given generators at random with (approximately) equal probability, and having it generate a value.- Type Parameters:
U- type of values produced by the resulting strategy- Parameters:
first- first possible generator choicerest- the other possible generator choices- Returns:
- a new generation strategy
-
frequency
@SafeVarargs static <U> Gen<U> frequency(Pair<Integer, Gen<? extends U>> first, Pair<Integer, Gen<? extends U>>... rest) Gives a generation strategy that produces a random value by choosing one of the given generators at random with probability in proportion to their given weights, and having it generate a value.- Type Parameters:
U- type of values produced by the resulting strategy- Parameters:
first- first possible (weighted) generator choicerest- the other possible (weighted) generator choices- Returns:
- a new generation strategy
-
freq
Helper for making a weighted generator indicator forfrequency(Pair, Pair[]).- Type Parameters:
U- type of values produced by the given generation strategy- Parameters:
weight- an integer weightgenerator- a generator- Returns:
- a weight-generator pair
-
_gen
Deprecated.For use by junit-quickcheck only -- when we migrate to Java 9 or better, this method will likely becomeprivate.- 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
-
private.