only:refactoring: make `IniFileModeImpl.metaInfo` field final #7357
This commit is contained in:
parent
706d8e1a8c
commit
c30e5dc468
|
@ -41,7 +41,7 @@ public class IniFileModelImpl implements IniFileModel {
|
||||||
private String currentXBins;
|
private String currentXBins;
|
||||||
private final Map<String, String> xBinsByZBins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
private final Map<String, String> xBinsByZBins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
private final Map<String, String> yBinsByZBins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
private final Map<String, String> yBinsByZBins = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
private IniFileMetaInfo metaInfo;
|
private final IniFileMetaInfo metaInfo;
|
||||||
|
|
||||||
private boolean isInSettingContextHelp = false;
|
private boolean isInSettingContextHelp = false;
|
||||||
private boolean isInsidePageDefinition;
|
private boolean isInsidePageDefinition;
|
||||||
|
@ -51,6 +51,10 @@ public class IniFileModelImpl implements IniFileModel {
|
||||||
return IniFileModelImpl.readIniFile(fileName);
|
return IniFileModelImpl.readIniFile(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IniFileModelImpl(@Nullable final IniFileMetaInfoImpl metaInfo) {
|
||||||
|
this.metaInfo = metaInfo;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<String>> getDefines() {
|
public Map<String, List<String>> getDefines() {
|
||||||
return defines;
|
return defines;
|
||||||
|
@ -88,14 +92,16 @@ public class IniFileModelImpl implements IniFileModel {
|
||||||
log.info("Reading " + fileName);
|
log.info("Reading " + fileName);
|
||||||
File input = new File(fileName);
|
File input = new File(fileName);
|
||||||
RawIniFile content = IniFileReader.read(input);
|
RawIniFile content = IniFileReader.read(input);
|
||||||
final IniFileModelImpl result = readIniFile(content);
|
return readIniFile(content, true);
|
||||||
result.metaInfo = new IniFileMetaInfoImpl(content);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IniFileModelImpl readIniFile(RawIniFile content) {
|
/**
|
||||||
final IniFileModelImpl result = new IniFileModelImpl();
|
* @param initMeta - part of our tests do not use `getMetaInfo` getter and will throw MandatoryLineMissing exception
|
||||||
|
* on attempt to create IniFileMetaInfoImpl instance from test data; to avoid this exception such
|
||||||
|
* tests should use `false` as value for this parameter
|
||||||
|
*/
|
||||||
|
public static IniFileModelImpl readIniFile(final RawIniFile content, final boolean initMeta) {
|
||||||
|
final IniFileModelImpl result = new IniFileModelImpl(initMeta ? new IniFileMetaInfoImpl(content) : null);
|
||||||
for (RawIniFile.Line line : content.getLines()) {
|
for (RawIniFile.Line line : content.getLines()) {
|
||||||
result.handleLine(line);
|
result.handleLine(line);
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class IniFileReaderTest {
|
||||||
"\t\tyBins\t\t= scriptCurve1\n" +
|
"\t\tyBins\t\t= scriptCurve1\n" +
|
||||||
"\t\tshowTextValues = true\n";
|
"\t\tshowTextValues = true\n";
|
||||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
IniFileModel model = IniFileModelImpl.readIniFile(lines);
|
IniFileModel model = IniFileModelImpl.readIniFile(lines, false);
|
||||||
assertEquals(2, model.getAllIniFields().size());
|
assertEquals(2, model.getAllIniFields().size());
|
||||||
assertEquals(2, model.getFieldsInUiOrder().size());
|
assertEquals(2, model.getFieldsInUiOrder().size());
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ public class IniFileReaderTest {
|
||||||
"\t\tyBins\t\t= tpsTpsAccelToRpmBins, TPSValue\n" +
|
"\t\tyBins\t\t= tpsTpsAccelToRpmBins, TPSValue\n" +
|
||||||
"\t\tzBins\t\t= tpsTpsAccelTable";
|
"\t\tzBins\t\t= tpsTpsAccelTable";
|
||||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
IniFileModel model = IniFileModelImpl.readIniFile(lines);
|
IniFileModel model = IniFileModelImpl.readIniFile(lines, false);
|
||||||
assertEquals(3, model.getAllIniFields().size());
|
assertEquals(3, model.getAllIniFields().size());
|
||||||
assertEquals(3, model.getFieldsInUiOrder().size());
|
assertEquals(3, model.getFieldsInUiOrder().size());
|
||||||
assertTrue(model.getFieldsInUiOrder().containsKey("tpsTpsAccelToRpmBins"));
|
assertTrue(model.getFieldsInUiOrder().containsKey("tpsTpsAccelToRpmBins"));
|
||||||
|
@ -165,7 +165,7 @@ public class IniFileReaderTest {
|
||||||
"\tlambdaTable\t\t\t\t\t = array, U08, 18592, [16x16],\"deg\", 0.1, 0, 0, 25.0, 1\n" +
|
"\tlambdaTable\t\t\t\t\t = array, U08, 18592, [16x16],\"deg\", 0.1, 0, 0, 25.0, 1\n" +
|
||||||
"#endif\n";
|
"#endif\n";
|
||||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
IniFileModel model = IniFileModelImpl.readIniFile(lines);
|
IniFileModel model = IniFileModelImpl.readIniFile(lines, false);
|
||||||
|
|
||||||
assertEquals(1, model.getAllIniFields().size());
|
assertEquals(1, model.getAllIniFields().size());
|
||||||
assertEquals(0, model.getFieldsInUiOrder().size()); // no UI for the field
|
assertEquals(0, model.getFieldsInUiOrder().size()); // no UI for the field
|
||||||
|
@ -180,7 +180,7 @@ public class IniFileReaderTest {
|
||||||
"primingSquirtDurationMs\t\t\t= scalar, F32,\t96,\t\"*C\", 1.0, 0, -40, 200, 1\n" +
|
"primingSquirtDurationMs\t\t\t= scalar, F32,\t96,\t\"*C\", 1.0, 0, -40, 200, 1\n" +
|
||||||
"";
|
"";
|
||||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
IniFileModel model = IniFileModelImpl.readIniFile(lines);
|
IniFileModel model = IniFileModelImpl.readIniFile(lines, false);
|
||||||
assertEquals(1, model.getAllIniFields().size());
|
assertEquals(1, model.getAllIniFields().size());
|
||||||
|
|
||||||
String crcProtocol = model.getProtocolMeta().get("crc32CheckCommand");
|
String crcProtocol = model.getProtocolMeta().get("crc32CheckCommand");
|
||||||
|
@ -199,7 +199,7 @@ public class IniFileReaderTest {
|
||||||
"\tiat_adcChannel\t\t\t\t = bits, U08, 312, [0:7] \"PA0\", \"PA1\", \"PA2\", \"PA3\", \"PA4\", \"PA5\", \"PA6\", \"PA7\", \"PB0\", \"PB1\", \"PC0\", \"PC1\", \"PC2\", \"PC3\", \"PC4\", \"PC5\", \"Disabled\", \"PB12\", \"PB13\", \"PC14\", \"PC15\", \"PC16\", \"PC17\", \"PD3\", \"PD4\", \"PE2\", \"PE6\", \"INVALID\", \"INVALID\", \"INVALID\", \"INVALID\", \"INVALID\"\n";
|
"\tiat_adcChannel\t\t\t\t = bits, U08, 312, [0:7] \"PA0\", \"PA1\", \"PA2\", \"PA3\", \"PA4\", \"PA5\", \"PA6\", \"PA7\", \"PB0\", \"PB1\", \"PC0\", \"PC1\", \"PC2\", \"PC3\", \"PC4\", \"PC5\", \"Disabled\", \"PB12\", \"PB13\", \"PC14\", \"PC15\", \"PC16\", \"PC17\", \"PD3\", \"PD4\", \"PE2\", \"PE6\", \"INVALID\", \"INVALID\", \"INVALID\", \"INVALID\", \"INVALID\"\n";
|
||||||
|
|
||||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
IniFileModel model = IniFileModelImpl.readIniFile(lines);
|
IniFileModel model = IniFileModelImpl.readIniFile(lines, false);
|
||||||
|
|
||||||
assertEquals(2, model.getAllIniFields().size());
|
assertEquals(2, model.getAllIniFields().size());
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ public class IniFileReaderTest {
|
||||||
"\tiat_adcChannel\t\t\t\t = bits, U08, 312, [0:7] $gpio_list\n";
|
"\tiat_adcChannel\t\t\t\t = bits, U08, 312, [0:7] $gpio_list\n";
|
||||||
|
|
||||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
IniFileModel model = IniFileModelImpl.readIniFile(lines);
|
IniFileModel model = IniFileModelImpl.readIniFile(lines, false);
|
||||||
assertEquals(1, model.getDefines().size());
|
assertEquals(1, model.getDefines().size());
|
||||||
|
|
||||||
EnumIniField field = (EnumIniField) model.getAllIniFields().get("iat_adcChannel");
|
EnumIniField field = (EnumIniField) model.getAllIniFields().get("iat_adcChannel");
|
||||||
|
@ -254,7 +254,7 @@ public class IniFileReaderTest {
|
||||||
"\tname\t= bits, U32, \t744, [3:5], \"false\", \"true\"";
|
"\tname\t= bits, U32, \t744, [3:5], \"false\", \"true\"";
|
||||||
|
|
||||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
IniFileModel model = IniFileModelImpl.readIniFile(lines);
|
IniFileModel model = IniFileModelImpl.readIniFile(lines, false);
|
||||||
|
|
||||||
assertEquals(1, model.getAllIniFields().size());
|
assertEquals(1, model.getAllIniFields().size());
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ public class IniFileReaderTest {
|
||||||
" \tname3\t\t\t= array, F32,\t108,\t[8],\t\"\", 1, 0, 0.0, 18000, 2\n";
|
" \tname3\t\t\t= array, F32,\t108,\t[8],\t\"\", 1, 0, 0.0, 18000, 2\n";
|
||||||
|
|
||||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
IniFileModel model = IniFileModelImpl.readIniFile(lines);
|
IniFileModel model = IniFileModelImpl.readIniFile(lines, false);
|
||||||
|
|
||||||
assertEquals(1, model.getAllIniFields().size());
|
assertEquals(1, model.getAllIniFields().size());
|
||||||
ArrayIniField field = (ArrayIniField) model.getAllIniFields().get("name");
|
ArrayIniField field = (ArrayIniField) model.getAllIniFields().get("name");
|
||||||
|
@ -294,7 +294,7 @@ public class IniFileReaderTest {
|
||||||
"#endif";
|
"#endif";
|
||||||
|
|
||||||
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
RawIniFile lines = IniFileReader.read(new ByteArrayInputStream(string.getBytes()));
|
||||||
IniFileModel model = IniFileModelImpl.readIniFile(lines);
|
IniFileModel model = IniFileModelImpl.readIniFile(lines, false);
|
||||||
|
|
||||||
assertEquals(1, model.getAllIniFields().size());
|
assertEquals(1, model.getAllIniFields().size());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue