public interface UniqueValues
| 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.
|
void setMaxRetries(int maxRetries)
maxRetries - how many times a random value may be generated during one invocation<T> T value(String uniquenessGroup, Supplier<T> supplier)
uniquenessGroup 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.T - the type of value to returnuniquenessGroup - id of the group within which the generated value should be uniquesupplier - the value supplierUniqueValueRetryLimitExceededException - if retry limit is exceeded<T> void within(Supplier<T> supplier, Consumer<Supplier<T>> within)
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.T - the type of value to returnsupplier - the value supplierwithin - the code within which the supplied values will be uniqueUniqueValueRetryLimitExceededException - if retry limit is exceeded<T,E> E of(Supplier<T> supplier, Function<Supplier<T>,E> collector)
Values 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.T - the type of value to returnsupplier - the value suppliercollector - the collector within which the supplied values will be uniqueUniqueValueRetryLimitExceededException - if retry limit is exceededCopyright © 2021. All rights reserved.