-
Notifications
You must be signed in to change notification settings - Fork 235
Grouping Randomizers
A RandomizerRegistry is a logical group of randomizers. A registry holds multiple randomizers targeted to a specific types support. The JodaTimeRandomizerRegistry is such an example, it groups all randomizers that support generating random values for Joda time types. The TimeRandomizerRegistry is another example that groups all randomizers to support Java 8 Date and Time types (JSR 310).
Internally, all randomizers are grouped into registries. Registries are ordered by priority as follows:
| Registry | Priority |
|---|---|
| InternalRandomizerRegistry | -4 |
| TimeRandomizerRegistry | -3 |
| JodatimeRandomizerRegistry | -3 |
| BeanValidationRandomizerRegistry | -2 |
| AnnotationRandomizerRegistry | -1 |
| CustomRandomizerRegistry | -1 |
| ExclusionRandomizerRegistry | 0 |
These priorities tell Random Beans the order in which it will use a randomizer for a given field.
You can create your own custom registry by implementing the RandomizerRegistry interface. Then, you can register it either:
In this case, you need to add a jar file in the class path specifying the provider implementation in META-INF/services and Random Beans will detect it automatically
EnhancedRandom enhancedRandom = EnhancedRandomBuilder.aNewEnhancedRandomBuilder()
.registerRandomizerRegistry(myRegistry)
.build();Finally, you need to set the priority of your registry by annotating your implementation class with @Priority. This annotation takes the priority of your registry as attribute. The priority of your registry should start form value 1 (higher values for higher priorities).
Easy Random is created by Mahmoud Ben Hassine with the help of some awesome contributors!