Commit f5326a4d authored by Toni Beier's avatar Toni Beier Committed by Toni Beier

ASiSTModuleManager class use map to store modules instances

Module map is a LinkedHashMap to keep insertion order.
Keys are the Class instance of the modules and the values are the module instances.
parent ee67a8e7
package de.bps.asist.core.manager;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import de.bps.asist.module.AbstractAsistModule;
......@@ -9,7 +11,7 @@ public class ASiSTModuleManager {
private static final ASiSTModuleManager INSTANCE = new ASiSTModuleManager();
private List<AbstractAsistModule> modules = new ArrayList<>();
private Map<Class<? extends AbstractAsistModule>, AbstractAsistModule> modules = new LinkedHashMap<>();
private ASiSTModuleManager(){
}
......@@ -19,22 +21,19 @@ public class ASiSTModuleManager {
}
public void resetModuleList(){
modules = new ArrayList<>();
this.modules.clear();
}
public void register(AbstractAsistModule module){
modules.add(module);
this.modules.put(module.getClass(), module);
}
public <T extends AbstractAsistModule> T getModule( Class<T> moduleClass, T defaultValue ) {
T resultModule = defaultValue;
for ( AbstractAsistModule registeredModule: this.modules ) {
if( moduleClass.isInstance( registeredModule ) ) {
defaultValue = (T)registeredModule;
break;
}
public <T extends AbstractAsistModule> T getModule(Class<T> moduleClass, T defaultValue ) {
T module = (T)this.modules.get(moduleClass);
if(module == null) {
module = defaultValue;
}
return resultModule;
return module;
}
public <T extends AbstractAsistModule> T getModule( Class<T> moduleClass) {
......@@ -42,7 +41,6 @@ public class ASiSTModuleManager {
}
public List<AbstractAsistModule> getModules() {
return modules;
return new ArrayList<>(modules.values());
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment