better method name

This commit is contained in:
rusefi 2017-12-11 11:41:19 -05:00
parent 20cea1b02b
commit f648fc96a9
3 changed files with 12 additions and 8 deletions

View File

@ -120,7 +120,7 @@ public class ConfigDefinition {
String line;
while ((line = fr.readLine()) != null) {
line = VariableRegistry.INSTANCE.processLine(line);
line = VariableRegistry.INSTANCE.applyVariables(line);
fw.write(line + ConfigDefinition.EOL);
}
fw.close();
@ -149,7 +149,7 @@ public class ConfigDefinition {
prefix.append(line + ConfigDefinition.EOL);
if (isAfterEndTag)
postfix.append(VariableRegistry.INSTANCE.processLine(line) + ConfigDefinition.EOL);
postfix.append(VariableRegistry.INSTANCE.applyVariables(line) + ConfigDefinition.EOL);
}
r.close();
return new TsFileContent(prefix.toString(), postfix.toString());
@ -206,7 +206,7 @@ public class ConfigDefinition {
String customSize = line.substring(0, index);
String tunerStudioLine = line.substring(index).trim();
tunerStudioLine = VariableRegistry.INSTANCE.processLine(tunerStudioLine);
tunerStudioLine = VariableRegistry.INSTANCE.applyVariables(tunerStudioLine);
int size;
try {
size = Integer.parseInt(customSize);

View File

@ -30,7 +30,11 @@ public class VariableRegistry extends TreeMap<String, String> {
super(String.CASE_INSENSITIVE_ORDER);
}
public String processLine(String line) {
/**
* This methos replaces variables references like @@var@@ with actual values
* An exception is thrown if we do not have such variable
*/
public String applyVariables(String line) {
Matcher m;
while ((m = VAR.matcher(line)).find()) {
String key = m.group(2);

View File

@ -15,9 +15,9 @@ public class VariableRegistryTest {
VariableRegistry.INSTANCE.register("var", 256);
assertEquals("256", VariableRegistry.INSTANCE.processLine("@@var@@"));
assertEquals("ab256", VariableRegistry.INSTANCE.processLine("ab@@var@@"));
assertEquals("ab256cd", VariableRegistry.INSTANCE.processLine("ab@@var@@cd"));
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.processLine("aa@@var@@qwe@@var_hex@@fff"));
assertEquals("256", VariableRegistry.INSTANCE.applyVariables("@@var@@"));
assertEquals("ab256", VariableRegistry.INSTANCE.applyVariables("ab@@var@@"));
assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd"));
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.applyVariables("aa@@var@@qwe@@var_hex@@fff"));
}
}