Drew reminds that humans like sorted drop downs #4339
This commit is contained in:
parent
9f2ec710db
commit
bf532e5c3e
Binary file not shown.
|
@ -21,7 +21,8 @@ public class PinoutLogic {
|
|||
|
||||
public static final String CONFIG_BOARDS = "config/boards/";
|
||||
private static final String CONNECTORS = "/connectors";
|
||||
private static final String QUOTED_NONE = quote("NONE");
|
||||
private static final String NONE = "NONE";
|
||||
private static final String QUOTED_NONE = quote(NONE);
|
||||
public static final String QUOTED_INVALID = quote(VariableRegistry.INVALID);
|
||||
|
||||
private final File[] boardYamlFiles;
|
||||
|
@ -97,27 +98,34 @@ public class PinoutLogic {
|
|||
@NotNull
|
||||
public static EnumPair enumToOptionsList(String nothingName, EnumsReader.EnumState enumList, ArrayList<String> values) {
|
||||
StringBuilder simpleForm = new StringBuilder();
|
||||
StringBuilder smartForm = new StringBuilder();
|
||||
|
||||
Map<Integer, String> pinMap = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
appendCommaIfNeeded(simpleForm);
|
||||
String key = findKey(enumList, i);
|
||||
|
||||
String value = values.get(i);
|
||||
if (i == 0) {
|
||||
pinMap.put(i, NONE);
|
||||
} else if (value != null) {
|
||||
pinMap.put(i, value);
|
||||
}
|
||||
if (key.equals(nothingName)) {
|
||||
simpleForm.append(QUOTED_NONE);
|
||||
appendCommaIfNeeded(smartForm);
|
||||
smartForm.append(i + "=" + QUOTED_NONE);
|
||||
|
||||
} else if (values.get(i) == null) {
|
||||
} else if (value == null) {
|
||||
simpleForm.append(QUOTED_INVALID);
|
||||
} else {
|
||||
appendCommaIfNeeded(smartForm);
|
||||
String quotedValue = quote(values.get(i));
|
||||
smartForm.append(i + "=" + quotedValue);
|
||||
String quotedValue = quote(value);
|
||||
simpleForm.append(quotedValue);
|
||||
}
|
||||
}
|
||||
String shorterForm = smartForm.length() < simpleForm.length() ? smartForm.toString() : simpleForm.toString();
|
||||
String keyValueForm = VariableRegistry.getHumanSortedTsKeyValueString(pinMap);
|
||||
return new EnumPair(keyValueForm, simpleForm.toString());
|
||||
|
||||
return new EnumPair(shorterForm, simpleForm.toString());
|
||||
// String shorterForm = smartForm.length() < simpleForm.length() ? smartForm.toString() : simpleForm.toString();
|
||||
//
|
||||
// return new EnumPair(shorterForm, simpleForm.toString());
|
||||
}
|
||||
|
||||
private static void appendCommaIfNeeded(StringBuilder sb) {
|
||||
|
|
|
@ -23,14 +23,14 @@ public class PinoutLogicTest {
|
|||
{
|
||||
ArrayList<String> list = new ArrayList<>(Arrays.asList("1", "NO", "10"));
|
||||
String result = PinoutLogic.enumToOptionsList("NO", enumState, list).getShorterForm();
|
||||
assertEquals("\"1\",\"NO\",\"10\"", result);
|
||||
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();
|
||||
assertEquals("0=\"1\",1=\"NO\",7=\"10\"", result);
|
||||
assertEquals("0=\"NONE\",7=\"10\",1=\"NO\"", result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue