prevent registering processor factories with same name as an existing one

This commit is contained in:
javanna 2016-01-06 11:34:02 +01:00 committed by Luca Cavanna
parent f651f5a531
commit 931d321d58
1 changed files with 6 additions and 7 deletions

View File

@ -28,14 +28,13 @@ public class ProcessorsRegistry {
private final Map<String, ProcessorFactoryProvider> processorFactoryProviders = new HashMap<>();
/**
* Adds a processor factory under a specific type name.
* Adds a processor factory under a specific name.
*/
public void addProcessor(String type, ProcessorFactoryProvider processorFactoryProvider) {
processorFactoryProviders.put(type, processorFactoryProvider);
}
public ProcessorFactoryProvider getProcessor(String type) {
return processorFactoryProviders.get(type);
public void addProcessor(String name, ProcessorFactoryProvider processorFactoryProvider) {
ProcessorFactoryProvider provider = processorFactoryProviders.putIfAbsent(name, processorFactoryProvider);
if (provider != null) {
throw new IllegalArgumentException("Processor factory already registered for name [" + name + "]");
}
}
public Set<Map.Entry<String, ProcessorFactoryProvider>> entrySet() {