X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fserializing%2FIdentifierGetter.java;h=7e2cfd802f5ac4f85439819d544fc9de6efff832;hb=8e8d5776ccc95a08885789834abd55cc50e18a24;hp=f1bb5f0b7f6861728471d013134e40873f0079d3;hpb=3977f16649531ca3ba345c9cd5ec365e0b804783;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IdentifierGetter.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IdentifierGetter.java index f1bb5f0b..7e2cfd80 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IdentifierGetter.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IdentifierGetter.java @@ -1,8 +1,17 @@ package net.mograsim.logic.model.serializing; +import static net.mograsim.logic.model.snippets.SubmodelComponentSnippetSuppliers.highLevelStateHandlerSupplier; +import static net.mograsim.logic.model.snippets.SubmodelComponentSnippetSuppliers.outlineRendererSupplier; +import static net.mograsim.logic.model.snippets.SubmodelComponentSnippetSuppliers.symbolRendererSupplier; +import static net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.StandardHighLevelStateHandlerSnippetSuppliers.atomicHandlerSupplier; +import static net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.StandardHighLevelStateHandlerSnippetSuppliers.subcomponentHandlerSupplier; + +import java.util.Map; +import java.util.Map.Entry; import java.util.function.Function; import net.mograsim.logic.model.model.components.GUIComponent; +import net.mograsim.logic.model.snippets.CodeSnippetSupplier; import net.mograsim.logic.model.snippets.HighLevelStateHandler; import net.mograsim.logic.model.snippets.Renderer; import net.mograsim.logic.model.snippets.highlevelstatehandlers.standard.atomic.AtomicHighLevelStateHandler; @@ -20,17 +29,33 @@ public class IdentifierGetter public Function atomicHighLevelStateHandlerIDs; /** - * Creates a new IdentifierGetter using "class:" concatenated with a component's / snippet's complete (canonical) class name as the - * default for all ID getter functions. + * Creates a new IdentifierGetter using the following as the default for all ID getter functions:
+ * Define the verbose ID as "class:" + canonicalClassName.
+ * If there is a standard ID mapping to this verbose ID recorded in the matching {@link CodeSnippetSupplier}, use this ID; if not, use + * the verbose ID. */ public IdentifierGetter() { - Function defaultSnippetIDGetter = c -> "class:" + c.getClass().getCanonicalName(); - this.componentIDs = defaultSnippetIDGetter::apply; - this.symbolRendererIDs = defaultSnippetIDGetter::apply; - this.outlineRendererIDs = defaultSnippetIDGetter::apply; - this.highLevelStateHandlerIDs = defaultSnippetIDGetter::apply; - this.subcomponentHighLevelStateHandlerIDs = defaultSnippetIDGetter::apply; - this.atomicHighLevelStateHandlerIDs = defaultSnippetIDGetter::apply; + componentIDs = generateStandardIDFunction(IndirectGUIComponentCreator.getStandardComponentIDs()); + symbolRendererIDs = generateStandardIDFunction(symbolRendererSupplier); + outlineRendererIDs = generateStandardIDFunction(outlineRendererSupplier); + highLevelStateHandlerIDs = generateStandardIDFunction(highLevelStateHandlerSupplier); + atomicHighLevelStateHandlerIDs = generateStandardIDFunction(atomicHandlerSupplier); + subcomponentHighLevelStateHandlerIDs = generateStandardIDFunction(subcomponentHandlerSupplier); + } + + private static Function generateStandardIDFunction(CodeSnippetSupplier snippetSupplier) + { + return generateStandardIDFunction(snippetSupplier.getStandardSnippetIDs()); + } + + private static Function generateStandardIDFunction(Map standardComponentIDs) + { + return t -> + { + String verboseID = "class:" + t.getClass().getCanonicalName(); + return standardComponentIDs.entrySet().stream().filter(e -> e.getValue().equals(verboseID)).map(Entry::getKey).findAny() + .orElse(verboseID); + }; } } \ No newline at end of file