Package org.instancio
Interface CartesianProductApi<T>
- Type Parameters:
T
- type to create
Provides an API for generating the Cartesian product.
- Since:
- 4.0.0
-
Method Summary
Modifier and TypeMethodDescriptionassign
(Assignment... assignments) <V> CartesianProductApi
<T> generate
(TargetSelector selector, GeneratorSpec<V> spec) <V> CartesianProductApi
<T> generate
(TargetSelector selector, GeneratorSpecProvider<V> gen) ignore
(TargetSelector selector) lenient()
list()
Returns he Cartesian product generated from values specified via thewith(TargetSelector, Object[])
method as a list.<V> CartesianProductApi
<T> onComplete
(TargetSelector selector, OnCompleteCallback<V> callback) <V> CartesianProductApi
<T> set
(TargetSelector selector, V value) subtype
(TargetSelector selector, Class<?> subtype) <V> CartesianProductApi
<T> supply
(TargetSelector selector, Supplier<V> supplier) <V> CartesianProductApi
<T> supply
(TargetSelector selector, Generator<V> generator) verbose()
<V> CartesianProductApi
<T> with
(TargetSelector selector, V... values) Sets a range of values for generating the Cartesian product.withMaxDepth
(int maxDepth) withNullable
(TargetSelector selector) withSeed
(long seed) withSettings
(Settings settings)
-
Method Details
-
with
Sets a range of values for generating the Cartesian product. The results are returned as a list in lexicographical order using thelist()
method.Example:
record Widget(String type, int num) {} List<Widget> results = Instancio.ofCartesianProduct(Widget.class) .with(field(Widget::type), "FOO", "BAR", "BAZ") .with(field(Widget::num), 1, 2, 3) .list();
This will produce the following list of
Widget
objects:[Widget[type=FOO, num=1], Widget[type=FOO, num=2], Widget[type=FOO, num=3], Widget[type=BAR, num=1], Widget[type=BAR, num=2], Widget[type=BAR, num=3], Widget[type=BAZ, num=1], Widget[type=BAZ, num=2], Widget[type=BAZ, num=3]]
Limitations
A selector passed to
with()
must match a single target. For example, Cartesian product cannot be generated for collection elements:record Widget(String type, int num) {} record Container(List<Widget> widgets) {} List<Container> results = Instancio.ofCartesianProduct(Container.class) .with(field(Widget::type), "FOO", "BAR", "BAZ") .with(field(Widget::num), 1, 2, 3) .list();
The above will produce an error with a message:
"no item is available to emit()"
.- Type Parameters:
V
- type of the value- Parameters:
selector
- for fields and/or classes this method should be applied tovalues
- the range of values to generate- Returns:
- API builder reference
- Since:
- 4.0.0
-
list
Returns he Cartesian product generated from values specified via thewith(TargetSelector, Object[])
method as a list.- Returns:
- Cartesian product as a list
- Since:
- 4.0.0
-
ignore
- Since:
- 4.0.0
-
withNullable
- Since:
- 4.0.0
-
set
- Since:
- 4.0.0
-
supply
- Since:
- 4.0.0
-
supply
- Since:
- 4.0.0
-
generate
- Since:
- 4.0.0
-
generate
@ExperimentalApi <V> CartesianProductApi<T> generate(TargetSelector selector, GeneratorSpec<V> spec) - Since:
- 4.0.0
-
onComplete
- Since:
- 4.0.0
-
subtype
- Since:
- 4.0.0
-
assign
- Since:
- 4.0.0
-
withMaxDepth
- Since:
- 4.0.0
-
withSettings
- Since:
- 4.0.0
-
withSeed
- Since:
- 4.0.0
-
lenient
CartesianProductApi<T> lenient()- Since:
- 4.0.0
-
verbose
CartesianProductApi<T> verbose()- Since:
- 4.0.0
-