@Experimental public final class DefaultUniqueValues extends Object implements UniqueValues
| Constructor and Description |
|---|
DefaultUniqueValues() |
| Modifier and Type | Method and Description |
|---|---|
<T,E> E |
of(Supplier<T> supplier,
Function<Supplier<T>,E> collector)
Allows for the creation of collections of unique values.
|
void |
setMaxRetries(int maxRetries) |
<T> T |
value(String uniquenessGroup,
Supplier<T> supplier)
Invokes supplier until it returns a value unique within
uniquenessGroup or the max retry limit is
reached. |
<T> void |
within(Supplier<T> supplier,
Consumer<Supplier<T>> within)
Guarantees supplied values to be unique within the context of the consumer's code.
|
public void setMaxRetries(int maxRetries)
setMaxRetries in interface UniqueValuesmaxRetries - how many times a random value may be generated during one invocationpublic <T> T value(String uniquenessGroup, Supplier<T> supplier)
UniqueValuesuniquenessGroup or the max retry limit is
reached.
The unique values will be referenced in memory for the lifetime of Dummy4j.
E.g. the following code:
String color1 = dummy4j.unique().value("colors", () -> dummy4j.color().basicName());
String color2 = dummy4j.unique().value("colors", () -> dummy4j.color().basicName());
will guarantee that the values of color1 and color2 will always be different from each other.value in interface UniqueValuesT - the type of value to returnuniquenessGroup - id of the group within which the generated value should be uniquesupplier - the value supplierpublic <T> void within(Supplier<T> supplier, Consumer<Supplier<T>> within)
UniqueValues
The unique values will be referenced in memory only until the execution of within is completed.
dummy.unique().within(() -> dummy.color().basicName(), color -> {
String color1 = color.get();
String color2 = color.get();
});
will guarantee that the values of color1 and color2 will always be different from each other.within in interface UniqueValuesT - the type of value to returnsupplier - the value supplierwithin - the code within which the supplied values will be uniquepublic <T,E> E of(Supplier<T> supplier, Function<Supplier<T>,E> collector)
UniqueValuesValues supplied within the collector function are guaranteed to be unique.
The unique values will be referenced in memory only until the execution of collector is completed.
List<String> colors = dummy.unique().of(() -> dummy.color().basicName(), color -> dummy.listOf(2, color));
will guarantee that the values of color will always be unique within the context of their list.of in interface UniqueValuesT - the type of value to returnsupplier - the value suppliercollector - the collector within which the supplied values will be uniqueCopyright © 2021. All rights reserved.