20 package net.sf.gridarta.gui.dialog.plugin.parameter.archetype;
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.Comparator;
26 import java.util.List;
27 import javax.swing.AbstractListModel;
28 import javax.swing.ComboBoxModel;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
36 public class ArchComboBoxModel<G
extends GameObject<G, A, R>, A extends
MapArchObject<A>, R extends
Archetype<G, A, R>> extends AbstractListModel<Archetype<G, A, R>> implements ComboBoxModel<Archetype<G, A, R>> {
42 private final List<Archetype<G, A, R>>
archList;
52 final Collection<R> archetypes = archetypeSet.getArchetypes();
53 archList =
new ArrayList<>(archetypes);
54 archList.sort((o1, o2) -> o1.getArchetypeName().toLowerCase().compareTo(o2.getArchetypeName().toLowerCase()));
79 public void setFilter(@NotNull
final String filter) {
89 fireContentsChanged(
this, 0,
archList.size());
92 private static int getCommonPrefix(@NotNull
final CharSequence s1, @NotNull
final CharSequence s2) {
94 while (s1.length() > i && s2.length() > i && s1.charAt(i) == s2.charAt(i)) {
109 @SuppressWarnings(
"TypeMayBeWeakened")
111 int pos = Collections.binarySearch(
archList,
name, (Comparator<Object>) (o1, o2) -> {
124 return s1.compareToIgnoreCase(s2);