From 1322c1dfacdb6324de241f034bf8b276b85acb26 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 12 Apr 2020 23:43:25 -0400 Subject: [PATCH] composition instead of inheritance --- .../src/com/rusefi/VariableRegistry.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java b/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java index cae4d11cbf..e3fd89298b 100644 --- a/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java +++ b/java_tools/configuration_definition/src/com/rusefi/VariableRegistry.java @@ -9,11 +9,13 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import static com.rusefi.ConfigDefinition.EOL; +import static com.rusefi.ReaderState.MULT_TOKEN; /** * 3/30/2015 */ -public class VariableRegistry extends TreeMap { +public class VariableRegistry { + private TreeMap data = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); public static final VariableRegistry INSTANCE = new VariableRegistry(); private final Pattern VAR = Pattern.compile("(@@(.*?)@@)"); @@ -24,7 +26,6 @@ public class VariableRegistry extends TreeMap { private final Map javaDefinitions = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); private VariableRegistry() { - super(String.CASE_INSENSITIVE_ORDER); } /** @@ -42,22 +43,22 @@ public class VariableRegistry extends TreeMap { // key = - if (!containsKey(key)) + if (!data.containsKey(key)) throw new IllegalStateException("No such variable: " + key); - String s = get(key); + String s = data.get(key); line = m.replaceFirst(s); } return line; } public void register(String var, String value) { - if (containsKey(var)) { + if (data.containsKey(var)) { SystemOut.println("Not redefining " + var); return; } value = applyVariables(value); SystemOut.println("Registering " + var + " as " + value); - put(var, value); + data.put(var, value); cAllDefinitions.put(var, "#define " + var + " " + value + EOL); tryToRegisterAsInteger(var, value); @@ -120,4 +121,18 @@ public class VariableRegistry extends TreeMap { result.append(value); return result.toString(); } + + public void clear() { + data.clear(); + cAllDefinitions.clear(); + javaDefinitions.clear(); + } + + public void put(String key, String value) { + data.put(key, value); + } + + public String get(Object key) { + return data.get(key); + } }