Package jsonvalues.gen
Interface JsGen<R extends JsValue>
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default <T extends JsValue>
JsGen<T>flatMap(java.util.function.Function<R,JsGen<T>> f)
Creates a new generator that passes the result of this generator into the given function `f`.default <T extends JsValue>
JsGen<T>map(java.util.function.Function<R,T> f)
Returns this generator but with the values transformed by the given map functiondefault JsGen<?>
nullable()
returns a new generator that generates the same elements as this generator and NULLdefault JsGen<?>
optional()
returns a new generator that generates the same elements as this generator and NOTHING.default java.util.function.Supplier<R>
sample()
Return a supplier of realized values from this generatordefault java.util.function.Supplier<R>
sample(java.util.Random random)
Return a supplier of realized values from this generator and the given seeddefault JsGen<R>
suchThat(java.util.function.Predicate<R> predicate)
Creates a generator that generates values from this generator that satisfy the given predicate.default JsGen<R>
suchThat(java.util.function.Predicate<R> predicate, int tries)
Creates a generator that generates values from this generator that satisfy the given predicate.
-
-
-
Method Detail
-
nullable
default JsGen<?> nullable()
returns a new generator that generates the same elements as this generator and NULL- Returns:
- a new generator
-
flatMap
default <T extends JsValue> JsGen<T> flatMap(java.util.function.Function<R,JsGen<T>> f)
Creates a new generator that passes the result of this generator into the given function `f`. `f` should return a new generator. This allows you to create new generators that depend on the value of other generators- Type Parameters:
T
- the type of the generated values- Parameters:
f
- the function- Returns:
- a generator
-
optional
default JsGen<?> optional()
returns a new generator that generates the same elements as this generator and NOTHING. Inserting NOTHING in a json removes the element. Comes in handy to generate Json objects with different keys.- Returns:
- a new generator
-
map
default <T extends JsValue> JsGen<T> map(java.util.function.Function<R,T> f)
Returns this generator but with the values transformed by the given map function- Type Parameters:
T
- type of the generated value- Parameters:
f
- map function- Returns:
- a new generator
-
sample
default java.util.function.Supplier<R> sample()
Return a supplier of realized values from this generator- Returns:
- a supplier of values
-
sample
default java.util.function.Supplier<R> sample(java.util.Random random)
Return a supplier of realized values from this generator and the given seed- Parameters:
random
- the seed of the generator- Returns:
- a supplier of values
-
suchThat
default JsGen<R> suchThat(java.util.function.Predicate<R> predicate)
Creates a generator that generates values from this generator that satisfy the given predicate. Care is needed to ensure there is a high chance this generator will satisfy the predicate. By default, `suchThat` will try 100 times to generate a value that satisfies the predicate. If no value passes this predicate after this number of iterations, a runtime exception will be thrown.- Parameters:
predicate
- the predicate satisfied by every generated value- Returns:
- a generator
-
suchThat
default JsGen<R> suchThat(java.util.function.Predicate<R> predicate, int tries)
Creates a generator that generates values from this generator that satisfy the given predicate. Care is needed to ensure there is a high chance this generator will satisfy the predicate. By default, `suchThat` will try specified number of times to generate a value that satisfies the predicate. If no value passes this predicate after this number of iterations, a runtime exception will be thrown.- Parameters:
predicate
- the predicate satisfied by every generated valuetries
- the number of tries- Returns:
- a generator
-
-