getIniField by name
This commit is contained in:
parent
a0943d139a
commit
6e49987f35
|
@ -1,6 +1,7 @@
|
|||
package com.opensr5.ini;
|
||||
|
||||
import com.opensr5.ini.field.IniField;
|
||||
import com.rusefi.config.Field;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -15,6 +16,9 @@ public interface IniFileModel {
|
|||
|
||||
Map<String, IniField> getAllIniFields();
|
||||
|
||||
IniField getIniField(Field field);
|
||||
|
||||
@Deprecated // always use 'Field' generated parameter with code-generated name?
|
||||
IniField getIniField(String key);
|
||||
|
||||
Map<String, String> getProtocolMeta();
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.opensr5.ini;
|
|||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.opensr5.ini.field.*;
|
||||
import com.rusefi.config.Field;
|
||||
import com.rusefi.core.FindFileHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -31,7 +32,7 @@ public class IniFileModelImpl implements IniFileModel {
|
|||
private final Map<String, DialogModel> dialogs = new TreeMap<>();
|
||||
// this is only used while reading model - TODO extract reader
|
||||
private final List<DialogModel.Field> fieldsOfCurrentDialog = new ArrayList<>();
|
||||
public Map<String, IniField> allIniFields = new LinkedHashMap<>();
|
||||
public Map<String, IniField> allIniFields = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
public final Map<String, DialogModel.Field> fieldsInUiOrder = new LinkedHashMap<>();
|
||||
|
||||
public Map</*field name*/String, String> tooltips = new TreeMap<>();
|
||||
|
@ -81,6 +82,11 @@ public class IniFileModelImpl implements IniFileModel {
|
|||
return allIniFields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IniField getIniField(Field field) {
|
||||
return getIniField(field.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IniField getIniField(String key) {
|
||||
IniField result = allIniFields.get(key);
|
||||
|
|
|
@ -20,12 +20,7 @@ public class MockIniFileProvider {
|
|||
|
||||
IniFileModel mockModel = mock(IniFileModel.class);
|
||||
when(mockModel.getMetaInfo()).thenReturn(mockMeta);
|
||||
when(mockModel.getIniField(any())).then(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||
return new StringIniField("mockStringIniField", 0, 12);
|
||||
}
|
||||
});
|
||||
when(mockModel.getIniField(anyString())).then(invocationOnMock -> new StringIniField("mockStringIniField", 0, 12));
|
||||
|
||||
return signature -> mockModel;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.opensr5.ini.IniFileModel;
|
|||
import com.opensr5.ini.field.StringIniField;
|
||||
import com.rusefi.ConnectionTab;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.config.generated.VariableRegistryValues;
|
||||
import com.rusefi.core.ui.AutoupdateUtil;
|
||||
import com.rusefi.io.ConnectionStatusLogic;
|
||||
|
@ -273,7 +274,7 @@ public class LuaScriptPanel {
|
|||
// todo: do we have "luaScript" as code-generated constant anywhere?
|
||||
IniFileModel iniFile = bp.getIniFile();
|
||||
Objects.requireNonNull(iniFile, "iniFile");
|
||||
return (StringIniField) iniFile.getIniField("luaScript");
|
||||
return (StringIniField) iniFile.getIniField(Fields.LUASCRIPT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
|
|
|
@ -2,7 +2,9 @@ package com.rusefi.tune;
|
|||
|
||||
import com.opensr5.ini.IniFileModel;
|
||||
import com.opensr5.ini.IniFileModelImpl;
|
||||
import com.opensr5.ini.field.StringIniField;
|
||||
import com.rusefi.*;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.tools.tune.TuneCanTool;
|
||||
import com.rusefi.tools.tune.TuneTools;
|
||||
import com.rusefi.tune.xml.Msq;
|
||||
|
@ -10,8 +12,7 @@ import com.rusefi.tune.xml.Page;
|
|||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class LoadOlderTuneTest {
|
||||
@Test
|
||||
|
@ -145,4 +146,11 @@ public class LoadOlderTuneTest {
|
|||
assertEquals(0, TuneTools.resolveEnumByName(tsCustomLine, "Single coil"));
|
||||
assertEquals(3, TuneTools.resolveEnumByName(tsCustomLine, "Two Distributors"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findFieldByName() {
|
||||
IniFileModel ini = IniFileModelImpl.readIniFile(TuneReadWriteTest.TEST_INI);
|
||||
StringIniField field = (StringIniField) ini.getIniField(Fields.ENGINEMAKE);
|
||||
assertNotNull(field);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue