Package net.datafaker.providers.base
Class Unique
This class contains methods that ensure uniqueness across separate invocations.
This can be helpful for unit tests and automated tests where certain values need to be different.
- Since:
- 1.6.0
-
Field Summary
Fields inherited from class net.datafaker.providers.base.AbstractProvider
faker
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfetchFromYaml
(String key) Returns a random value from the YAML files that is guaranteed to be unique for the given key and locale set on the current faker instance.
-
Constructor Details
-
Unique
-
-
Method Details
-
fetchFromYaml
Returns a random value from the YAML files that is guaranteed to be unique for the given key and locale set on the current faker instance.Since unique values are tracked by both the key and the locale, manually changing the locale could cause this method to return the same value for a given key if there is not a separate locale for the given key.
- Parameters:
key
- the key of the values to fetch from the YAML files- Returns:
- a unique random value based on
key
and the current locale - Throws:
NoSuchElementException
- ifkey
does not correspond to a list of valid data types in the YAML files, or if all possible values found forkey
and current locale have been returned
-