better method name
This commit is contained in:
parent
20cea1b02b
commit
f648fc96a9
|
@ -120,7 +120,7 @@ public class ConfigDefinition {
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
while ((line = fr.readLine()) != null) {
|
while ((line = fr.readLine()) != null) {
|
||||||
line = VariableRegistry.INSTANCE.processLine(line);
|
line = VariableRegistry.INSTANCE.applyVariables(line);
|
||||||
fw.write(line + ConfigDefinition.EOL);
|
fw.write(line + ConfigDefinition.EOL);
|
||||||
}
|
}
|
||||||
fw.close();
|
fw.close();
|
||||||
|
@ -149,7 +149,7 @@ public class ConfigDefinition {
|
||||||
prefix.append(line + ConfigDefinition.EOL);
|
prefix.append(line + ConfigDefinition.EOL);
|
||||||
|
|
||||||
if (isAfterEndTag)
|
if (isAfterEndTag)
|
||||||
postfix.append(VariableRegistry.INSTANCE.processLine(line) + ConfigDefinition.EOL);
|
postfix.append(VariableRegistry.INSTANCE.applyVariables(line) + ConfigDefinition.EOL);
|
||||||
}
|
}
|
||||||
r.close();
|
r.close();
|
||||||
return new TsFileContent(prefix.toString(), postfix.toString());
|
return new TsFileContent(prefix.toString(), postfix.toString());
|
||||||
|
@ -206,7 +206,7 @@ public class ConfigDefinition {
|
||||||
String customSize = line.substring(0, index);
|
String customSize = line.substring(0, index);
|
||||||
|
|
||||||
String tunerStudioLine = line.substring(index).trim();
|
String tunerStudioLine = line.substring(index).trim();
|
||||||
tunerStudioLine = VariableRegistry.INSTANCE.processLine(tunerStudioLine);
|
tunerStudioLine = VariableRegistry.INSTANCE.applyVariables(tunerStudioLine);
|
||||||
int size;
|
int size;
|
||||||
try {
|
try {
|
||||||
size = Integer.parseInt(customSize);
|
size = Integer.parseInt(customSize);
|
||||||
|
|
|
@ -30,7 +30,11 @@ public class VariableRegistry extends TreeMap<String, String> {
|
||||||
super(String.CASE_INSENSITIVE_ORDER);
|
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;
|
Matcher m;
|
||||||
while ((m = VAR.matcher(line)).find()) {
|
while ((m = VAR.matcher(line)).find()) {
|
||||||
String key = m.group(2);
|
String key = m.group(2);
|
||||||
|
|
|
@ -15,9 +15,9 @@ public class VariableRegistryTest {
|
||||||
|
|
||||||
VariableRegistry.INSTANCE.register("var", 256);
|
VariableRegistry.INSTANCE.register("var", 256);
|
||||||
|
|
||||||
assertEquals("256", VariableRegistry.INSTANCE.processLine("@@var@@"));
|
assertEquals("256", VariableRegistry.INSTANCE.applyVariables("@@var@@"));
|
||||||
assertEquals("ab256", VariableRegistry.INSTANCE.processLine("ab@@var@@"));
|
assertEquals("ab256", VariableRegistry.INSTANCE.applyVariables("ab@@var@@"));
|
||||||
assertEquals("ab256cd", VariableRegistry.INSTANCE.processLine("ab@@var@@cd"));
|
assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd"));
|
||||||
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.processLine("aa@@var@@qwe@@var_hex@@fff"));
|
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.applyVariables("aa@@var@@qwe@@var_hex@@fff"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue