Commit 7bd74930 authored by Toni Beier's avatar 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;
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(){
......@@ -18,23 +20,20 @@ public class ASiSTModuleManager {
return INSTANCE;
public void resetModuleList(){
modules = new ArrayList<>();
public void resetModuleList() {
public void register(AbstractAsistModule module){
public void register(AbstractAsistModule 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;
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