X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fsnippets%2Fhighlevelstatehandlers%2Fstandard%2FStandardHighLevelStateHandler.java;h=1c3ac62c6f2da999fb1b7f5955105d1e0040a313;hb=c310e267d7c8a1003d21c9bbae02b9186a95cd10;hp=ec3b04d95e70e84c5574bf20ef53965f7091b65e;hpb=d333df14f718d96b419d751c6b2c64c6375726a8;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/StandardHighLevelStateHandler.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/StandardHighLevelStateHandler.java index ec3b04d9..1c3ac62c 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/StandardHighLevelStateHandler.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/snippets/highlevelstatehandlers/standard/StandardHighLevelStateHandler.java @@ -2,8 +2,10 @@ package net.mograsim.logic.model.snippets.highlevelstatehandlers.standard; import java.util.HashMap; import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Function; -import net.mograsim.logic.model.model.components.GUIComponent; +import net.mograsim.logic.model.model.components.submodels.SubmodelComponent; import net.mograsim.logic.model.snippets.HighLevelStateHandler; import net.mograsim.logic.model.snippets.SnippetDefinintion; import net.mograsim.logic.model.snippets.SubmodelComponentSnippetSuppliers; @@ -14,24 +16,48 @@ import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.subcomp public class StandardHighLevelStateHandler implements HighLevelStateHandler { - private final GUIComponent component; + private final SubmodelComponent component; private final Map subcomponentHighLevelStateHandlers; private final Map atomicHighLevelStateHandlers; - public StandardHighLevelStateHandler(GUIComponent component, SimpleHighLevelStateHandlerParams params) + public StandardHighLevelStateHandler(SubmodelComponent component) + { + this(component, null); + } + + public StandardHighLevelStateHandler(SubmodelComponent component, StandardHighLevelStateHandlerParams params) { this.component = component; this.subcomponentHighLevelStateHandlers = new HashMap<>(); this.atomicHighLevelStateHandlers = new HashMap<>(); - params.subcomponentHighLevelStates.forEach(this::addSubcomponentHighLevelState); - params.atomicHighLevelStates.forEach(this::addAtomicHighLevelState); + if (params != null) + { + params.subcomponentHighLevelStates.forEach(this::addSubcomponentHighLevelState); + params.atomicHighLevelStates.forEach(this::addAtomicHighLevelState); + } + } + + public SubcomponentHighLevelStateHandler addSubcomponentHighLevelState(String subcomponentStateID, + SubcomponentHighLevelStateHandlerParams handlerParams) + { + return addSubcomponentHighLevelState(subcomponentStateID, + StandardHighLevelStateHandlerSnippetSuppliers.subcomponentHandlerSupplier.getSnippetSupplier(handlerParams.id)::create, + handlerParams.params); + } + + public H addSubcomponentHighLevelState(String subcomponentStateID, + BiFunction handlerConstructor, P handlerParams) + { + return addSubcomponentHighLevelState(subcomponentStateID, c -> handlerConstructor.apply(c, handlerParams)); } - public void addSubcomponentHighLevelState(String subcomponentStateID, SubcomponentHighLevelStateHandlerParams handlerParams) + public H addSubcomponentHighLevelState(String subcomponentStateID, + Function handlerConstructor) { HighLevelStateHandlerContext context = new HighLevelStateHandlerContext(component, subcomponentStateID); - addSubcomponentHighLevelState(subcomponentStateID, StandardHighLevelStateHandlerSnippetSuppliers.subcomponentHandlerSupplier - .getSnippetSupplier(handlerParams.id).create(context, handlerParams.params)); + H handler = handlerConstructor.apply(context); + addSubcomponentHighLevelState(subcomponentStateID, handler); + return handler; } public void addSubcomponentHighLevelState(String subcomponentStateID, SubcomponentHighLevelStateHandler handler) @@ -40,11 +66,26 @@ public class StandardHighLevelStateHandler implements HighLevelStateHandler subcomponentHighLevelStateHandlers.put(subcomponentStateID, handler); } - public void addAtomicHighLevelState(String atomicStateID, AtomicHighLevelStateHandlerParams handlerParams) + public AtomicHighLevelStateHandler addAtomicHighLevelState(String atomicStateID, AtomicHighLevelStateHandlerParams handlerParams) + { + return addAtomicHighLevelState(atomicStateID, + StandardHighLevelStateHandlerSnippetSuppliers.atomicHandlerSupplier.getSnippetSupplier(handlerParams.id)::create, + handlerParams.params); + } + + public H addAtomicHighLevelState(String subcomponentStateID, + BiFunction handlerConstructor, P handlerParams) { - HighLevelStateHandlerContext context = new HighLevelStateHandlerContext(component, atomicStateID); - addSubcomponentHighLevelState(atomicStateID, StandardHighLevelStateHandlerSnippetSuppliers.subcomponentHandlerSupplier - .getSnippetSupplier(handlerParams.id).create(context, handlerParams.params)); + return addAtomicHighLevelState(subcomponentStateID, c -> handlerConstructor.apply(c, handlerParams)); + } + + public H addAtomicHighLevelState(String subcomponentStateID, + Function handlerConstructor) + { + HighLevelStateHandlerContext context = new HighLevelStateHandlerContext(component, subcomponentStateID); + H handler = handlerConstructor.apply(context); + addAtomicHighLevelState(subcomponentStateID, handler); + return handler; } public void addAtomicHighLevelState(String atomicStateID, AtomicHighLevelStateHandler handler) @@ -98,7 +139,7 @@ public class StandardHighLevelStateHandler implements HighLevelStateHandler } } - public static class SimpleHighLevelStateHandlerParams + public static class StandardHighLevelStateHandlerParams { public Map subcomponentHighLevelStates; public Map atomicHighLevelStates; @@ -108,6 +149,6 @@ public class StandardHighLevelStateHandler implements HighLevelStateHandler { SubmodelComponentSnippetSuppliers.highLevelStateHandlerSupplier.setSnippetSupplier( StandardHighLevelStateHandler.class.getCanonicalName(), - SnippetDefinintion.create(SimpleHighLevelStateHandlerParams.class, StandardHighLevelStateHandler::new)); + SnippetDefinintion.create(StandardHighLevelStateHandlerParams.class, StandardHighLevelStateHandler::new)); } } \ No newline at end of file