Class GeneratorRegistry
- Direct Known Subclasses:
GeneratorFactory
GeneratorRegistry is central static registry that manages all Generator
instances within the mocka-core library.
It provides static methods to register, retrieve, and manage generators identified by unique keys.
The registry is backed by a thread-safe ConcurrentHashMap, ensuring safe concurrent access.
By default, several common generators (e.g. EmailGenerator, NameGenerator,
CountryGenerator) are registered in the static initializer.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidRemoves all registered RegistrableGenerators from the registry.static voidstatic BooleanChecks whether a generator with the given key exists in the registry.static <T> Generator<T>getGenerator(String key) Retrieves a registeredGeneratorby its unique key.static <T> Generator<T>getGenerator(String key, String path, Class<T> type) Retrieves aRegistrableGeneratorfor the given key.Returns the list of all keys (names) of registered generators.static <T> voidputGenerator(String key, String path, Class<T> type) CreatesRegistrableGeneratorby key, path, and type parameters and registers the Generator.static <T> voidputGenerator(T generator) Registers the givenGeneratorinto the Registry.
-
Field Details
-
GENERATOR_MAP
-
-
Constructor Details
-
GeneratorRegistry
public GeneratorRegistry()
-
-
Method Details
-
putGenerator
public static <T> void putGenerator(T generator) Registers the givenGeneratorinto the Registry.if
GeneratorimplementsRegistrableGenerator, the Generator put as RegistrableGenerator. ifGeneratorimplementsAbstractGenerator, the Generator put as Generator extends AbstractGenerator.- Type Parameters:
T- the type of value to be generated- Parameters:
generator- the generator to register- Throws:
UnsupportedOperationException- if the generator type is not supported.
-
putGenerator
CreatesRegistrableGeneratorby key, path, and type parameters and registers the Generator.- Type Parameters:
T- the type parameter of the generator- Parameters:
key- unique identifier of the generatorpath- file path used as the source for the generatortype- the type of data the generator produces- Throws:
GeneratorException- if a generator with the same key already exists
-
getGenerator
Retrieves a registeredGeneratorby its unique key.- Type Parameters:
T- the type parameter of the generator- Parameters:
key- unique identifier of the generator- Returns:
- the
Generatorregistered under the given key - Throws:
GeneratorException- if no generator is found for the given key
-
getGenerator
Retrieves aRegistrableGeneratorfor the given key.If a generator with the specified key does not exist, a new one is created with the provided
pathandtype, registered, and then returned.- Type Parameters:
T- the type parameter of the generator- Parameters:
key- unique identifier of the generatorpath- file path used as the source for the generatortype- the type of data the generator produces- Returns:
- the existing or newly created
Generator
-
clearAllRegistrableGenerator
public static void clearAllRegistrableGenerator()Removes all registered RegistrableGenerators from the registry. Built-in generators (e.g.EmailGenerator,NameGenerator) are not affected and remain registered.After calling this method, any custom
RegistrableGeneratormust be registered again before use. -
clearRegistrableGenerator
-
getGeneratorNames
Returns the list of all keys (names) of registered generators.- Returns:
- a list of generator keys currently registered
-
existsRegistrableGenerator
Checks whether a generator with the given key exists in the registry.- Parameters:
key- the unique identifier of the generator- Returns:
trueif a generator is registered under the given key,falseotherwise
-