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