refactoring

This commit is contained in:
rusefi 2019-05-18 08:24:29 -04:00
parent 15a610d7a7
commit 666894e267
6 changed files with 37 additions and 19 deletions

View File

@ -1,7 +1,9 @@
package com.rusefi;
import java.io.*;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* (c) Andrey Belomutskiy
@ -117,7 +119,10 @@ public class ConfigDefinition {
ConfigurationConsumer javaFieldsConcumer) throws IOException {
String line;
cHeaderConsumer.startFile();
List<ConfigurationConsumer> consumers = Arrays.asList(cHeaderConsumer, tsProjectConsumer, javaFieldsConcumer);
for (ConfigurationConsumer consumer : consumers)
consumer.startFile();
while ((line = definitionReader.readLine()) != null) {
line = trimLine(line);
@ -149,9 +154,8 @@ public class ConfigDefinition {
processField(state, line);
}
}
cHeaderConsumer.endFile();
tsProjectConsumer.endFile();
javaFieldsConcumer.endFile();
for (ConfigurationConsumer consumer : consumers)
consumer.endFile();
}
private static boolean isEmptyDefinitionLine(String line) {

View File

@ -1,6 +1,6 @@
package com.rusefi;
import com.rusefi.test.ConfigDefinitionTest;
import com.rusefi.test.ConfigFieldParserTest;
import java.io.IOException;
import java.io.Writer;
@ -73,7 +73,7 @@ public class ConfigField {
}
/**
* @see ConfigDefinitionTest#testParseLine()
* @see ConfigFieldParserTest#testParseLine()
*/
public static ConfigField parse(ReaderState state, String line) {
Matcher matcher = FIELD.matcher(line);

View File

@ -28,8 +28,9 @@ public class VariableRegistry extends TreeMap<String, String> {
}
/**
* This methos replaces variables references like @@var@@ with actual values
* This method replaces variables references like @@var@@ with actual values
* An exception is thrown if we do not have such variable
* @return string with variable values inlined
*/
public String applyVariables(String line) {
Matcher m;
@ -85,9 +86,12 @@ public class VariableRegistry extends TreeMap<String, String> {
return value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"';
}
public void register(String var, int i) {
register(var, Integer.toString(i));
register(var + "_hex", Integer.toString(i, 16));
/**
* Registers decimal and hex versions of this integer variable
*/
public void register(String name, int value) {
register(name, Integer.toString(value));
register(name + "_hex", Integer.toString(value, 16));
}
public void writeNumericsToFile(String headerDestinationFolder) throws IOException {

View File

@ -0,0 +1,16 @@
package com.rusefi.test;
import com.rusefi.ConfigDefinition;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ConfigDefinitionOutputTest {
@Test
public void testComment() {
assertEquals("", ConfigDefinition.packComment("", "\t"));
assertEquals("\t * abc\n", ConfigDefinition.packComment("abc", "\t"));
assertEquals("\t * abc\n" +
"\t * vbn\n", ConfigDefinition.packComment("abc\\nvbn", "\t"));
}
}

View File

@ -11,14 +11,7 @@ import static org.junit.Assert.*;
* (c) Andrey Belomutskiy
* 1/15/15
*/
public class ConfigDefinitionTest {
@Test
public void testComment() {
assertEquals("", ConfigDefinition.packComment("", "\t"));
assertEquals("\t * abc\n", ConfigDefinition.packComment("abc", "\t"));
assertEquals("\t * abc\n" +
"\t * vbn\n", ConfigDefinition.packComment("abc\\nvbn", "\t"));
}
public class ConfigFieldParserTest {
@Test
public void testByteArray() {
@ -30,7 +23,6 @@ public class ConfigDefinitionTest {
assertEquals(cf.getSize(null), 8);
assertFalse("isIterate", cf.isIterate);
}
}
@Test

View File

@ -15,9 +15,11 @@ public class VariableRegistryTest {
VariableRegistry.INSTANCE.register("var", 256);
// trivial key-value substitution
assertEquals("256", VariableRegistry.INSTANCE.applyVariables("@@var@@"));
assertEquals("ab256", VariableRegistry.INSTANCE.applyVariables("ab@@var@@"));
assertEquals("ab256cd", VariableRegistry.INSTANCE.applyVariables("ab@@var@@cd"));
// both decimal and hex values here
assertEquals("aa256qwe100fff", VariableRegistry.INSTANCE.applyVariables("aa@@var@@qwe@@var_hex@@fff"));
}
}