only:better method name
This commit is contained in:
parent
2423d4d332
commit
d09f464801
|
@ -1,19 +1,19 @@
|
|||
package com.rusefi;
|
||||
|
||||
public class EnumPair {
|
||||
private final String shorterForm;
|
||||
private final String simpleForm;
|
||||
private final String keyValueForm;
|
||||
private final String arrayForm;
|
||||
|
||||
public EnumPair(String shorterForm, String simpleForm) {
|
||||
this.shorterForm = shorterForm;
|
||||
this.simpleForm = simpleForm;
|
||||
public EnumPair(String keyValueForm, String arrayForm) {
|
||||
this.keyValueForm = keyValueForm;
|
||||
this.arrayForm = arrayForm;
|
||||
}
|
||||
|
||||
public String getShorterForm() {
|
||||
return shorterForm;
|
||||
public String getKeyValueForm() {
|
||||
return keyValueForm;
|
||||
}
|
||||
|
||||
public String getSimpleForm() {
|
||||
return simpleForm;
|
||||
public String getArrayForm() {
|
||||
return arrayForm;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,22 +81,23 @@ public class PinoutLogic {
|
|||
String nothingName = namePinType.getNothingName();
|
||||
EnumsReader.EnumState enumList = enumsReader.getEnums().get(pinType);
|
||||
EnumPair pair = enumToOptionsList(nothingName, enumList, kv.getValue());
|
||||
if (pair.getSimpleForm().length() > 0) {
|
||||
if (pair.getArrayForm().length() > 0) {
|
||||
// we seem to be here if specific pin category like switch_inputs has no pins
|
||||
parseState.addDefinition(registry, outputEnumName + ENUM_SUFFIX, pair.getShorterForm(), Definition.OverwritePolicy.IgnoreNew);
|
||||
parseState.addDefinition(registry, outputEnumName + ENUM_SUFFIX, pair.getKeyValueForm(), Definition.OverwritePolicy.IgnoreNew);
|
||||
}
|
||||
parseState.addDefinition(registry, outputEnumName + FULL_JAVA_ENUM, pair.getSimpleForm(), Definition.OverwritePolicy.IgnoreNew);
|
||||
parseState.addDefinition(registry, outputEnumName + FULL_JAVA_ENUM, pair.getArrayForm(), Definition.OverwritePolicy.IgnoreNew);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static EnumPair enumToOptionsList(String nothingName, EnumsReader.EnumState enumList, ArrayList<String> values) {
|
||||
StringBuilder simpleForm = new StringBuilder();
|
||||
// "value0", "value1", "value2" format
|
||||
StringBuilder arrayFormat = new StringBuilder();
|
||||
|
||||
Map<Integer, String> pinMap = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
appendCommaIfNeeded(simpleForm);
|
||||
appendCommaIfNeeded(arrayFormat);
|
||||
String key = enumList.findByValue(i);
|
||||
|
||||
String value = values.get(i);
|
||||
|
@ -106,16 +107,17 @@ public class PinoutLogic {
|
|||
pinMap.put(i, value);
|
||||
}
|
||||
if (key.equals(nothingName)) {
|
||||
simpleForm.append(QUOTED_NONE);
|
||||
arrayFormat.append(QUOTED_NONE);
|
||||
} else if (value == null) {
|
||||
simpleForm.append(QUOTED_INVALID);
|
||||
arrayFormat.append(QUOTED_INVALID);
|
||||
} else {
|
||||
String quotedValue = quote(value);
|
||||
simpleForm.append(quotedValue);
|
||||
arrayFormat.append(quotedValue);
|
||||
}
|
||||
}
|
||||
// 2="Value2",5="value5" format
|
||||
String keyValueForm = VariableRegistry.getHumanSortedTsKeyValueString(pinMap);
|
||||
return new EnumPair(keyValueForm, simpleForm.toString());
|
||||
return new EnumPair(keyValueForm, arrayFormat.toString());
|
||||
}
|
||||
|
||||
private static void appendCommaIfNeeded(StringBuilder sb) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.rusefi.pinout;
|
||||
|
||||
import com.rusefi.EnumsReader;
|
||||
import com.rusefi.pinout.PinoutLogic;
|
||||
import com.rusefi.enum_reader.Value;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -22,14 +21,14 @@ public class PinoutLogicTest {
|
|||
|
||||
{
|
||||
ArrayList<String> list = new ArrayList<>(Arrays.asList("1", "NO", "10"));
|
||||
String result = PinoutLogic.enumToOptionsList("NO", enumState, list).getShorterForm();
|
||||
String result = PinoutLogic.enumToOptionsList("NO", enumState, list).getKeyValueForm();
|
||||
assertEquals("0=\"NONE\",2=\"10\",1=\"NO\"", result);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
ArrayList<String> list = new ArrayList<>(Arrays.asList("1", "NO", null, null, null, null, null, "10"));
|
||||
String result = PinoutLogic.enumToOptionsList("NO", enumState, list).getShorterForm();
|
||||
String result = PinoutLogic.enumToOptionsList("NO", enumState, list).getKeyValueForm();
|
||||
assertEquals("0=\"NONE\",7=\"10\",1=\"NO\"", result);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue