X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fserializing%2FIndirectGUIComponentCreator.java;h=a7550b8cf9a6f565763337f1b3beb4206b41b4b4;hb=d6702bcad356a28bc6c2eb0574d5cecdf536aabc;hp=23f8bcb8d82daefb3f35459b855e7229b355c306;hpb=a393b0a2a9899707af54c9ee77a01f28ac967bd1;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java index 23f8bcb8..a7550b8c 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/IndirectGUIComponentCreator.java @@ -3,9 +3,10 @@ package net.mograsim.logic.model.serializing; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; -import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Set; import com.google.gson.JsonElement; import com.google.gson.JsonNull; @@ -18,6 +19,7 @@ import net.mograsim.logic.model.util.JsonHandler; public class IndirectGUIComponentCreator { private static final Map standardComponentIDs = new HashMap<>(); + private static final Set standardComponentIDSetUnmodifiable = Collections.unmodifiableSet(standardComponentIDs.keySet()); private static final Map componentSuppliers = new HashMap<>(); @@ -54,9 +56,9 @@ public class IndirectGUIComponentCreator standardComponentIDs.put(standardComponentID, associatedComponentID); } - public static Collection getStandardComponentIDs() + public static Set getStandardComponentIDs() { - return standardComponentIDs.keySet(); + return standardComponentIDSetUnmodifiable; } public static void setComponentSupplier(String className, ComponentSupplier componentSupplier) @@ -88,25 +90,28 @@ public class IndirectGUIComponentCreator resolvedID = id; else resolvedID = standardComponentIDs.get(id); - if (resolvedID.startsWith("class:")) + if (resolvedID != null) { - String className = resolvedID.substring(6); - tryLoadComponentClass(className); - ComponentSupplier componentSupplier = componentSuppliers.get(className); - if (componentSupplier != null) - return componentSupplier.create(model, params, name); - } else - // we know id has to start with "file:" here - // because standardComponentIDs only contains strings starting with "class:" or "file:" - if (params != null && !JsonNull.INSTANCE.equals(params)) - throw new IllegalArgumentException("Can't give params to a component deserialized from a JSON file"); - try - { - return SubmodelComponentSerializer.deserialize(model, resolvedID.substring(5), name, id, null); - } - catch (IOException e) - { - throw new UncheckedIOException(e); + if (resolvedID.startsWith("class:")) + { + String className = resolvedID.substring(6); + tryLoadComponentClass(className); + ComponentSupplier componentSupplier = componentSuppliers.get(className); + if (componentSupplier != null) + return componentSupplier.create(model, params, name); + } else + // we know id has to start with "file:" here + // because standardComponentIDs only contains strings starting with "class:" or "file:" + if (params != null && !JsonNull.INSTANCE.equals(params)) + throw new IllegalArgumentException("Can't give params to a component deserialized from a JSON file"); + try + { + return SubmodelComponentSerializer.deserialize(model, resolvedID.substring(5), name, id, null); + } + catch (IOException e) + { + throw new UncheckedIOException(e); + } } } throw new RuntimeException("Could not get component supplier for ID " + id);