Restore old sorting behaviour

- In #946 we added new ways to add items to single selector while still
  keeping Map<String, String>. Order to keep old sorting behaviour
  we try to pass incoming map via new HashMap as that was a way it
  worked. This should limit risks for breaking things in a patch release.
This commit is contained in:
Janne Valkealahti
2023-12-23 10:02:06 +00:00
parent 4eab8be5d0
commit cb8f44ff63

View File

@@ -17,6 +17,7 @@ package org.springframework.shell.component.flow;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
@@ -81,7 +82,11 @@ public abstract class BaseSingleItemSelector extends BaseInput<SingleItemSelecto
@Override
public SingleItemSelectorSpec selectItems(Map<String, String> selectItems) {
List<SelectItem> items = selectItems.entrySet().stream()
// TODO: we changed to keep items as SelectItem's, to try to keep old sorting
// behaviour we go via HashMap gh-946. Later we should remove this step.
Map<String, String> selectItemsMap = new HashMap<>();
selectItemsMap.putAll(selectItems);
List<SelectItem> items = selectItemsMap.entrySet().stream()
.map(e -> SelectItem.of(e.getKey(), e.getValue()))
.collect(Collectors.toList());
selectItems(items);