Libraries that contain type "Arduino" are now listed at the top. Fixes #4195

This commit is contained in:
Federico Fissore 2015-11-23 16:15:37 +01:00
parent bfeb994974
commit ceef83dbb9
2 changed files with 29 additions and 2 deletions

View File

@ -29,13 +29,40 @@
package cc.arduino.contributions.libraries.ui;
import cc.arduino.contributions.libraries.ContributedLibrary;
import java.util.Comparator;
public class ContributedLibraryReleasesComparator implements Comparator<ContributedLibraryReleases> {
private final String firstType;
public ContributedLibraryReleasesComparator(String firstType) {
this.firstType = firstType;
}
@Override
public int compare(ContributedLibraryReleases o1, ContributedLibraryReleases o2) {
return o1.getLibrary().getName().compareToIgnoreCase(o2.getLibrary().getName());
ContributedLibrary lib1 = o1.getLibrary();
ContributedLibrary lib2 = o2.getLibrary();
if (lib1.getTypes() == null || lib2.getTypes() == null) {
return compareName(lib1, lib2);
}
if (lib1.getTypes().contains(firstType) && lib2.getTypes().contains(firstType)) {
return compareName(lib1, lib2);
}
if (lib1.getTypes().contains(firstType)) {
return -1;
}
if (lib2.getTypes().contains(firstType)) {
return 1;
}
return compareName(lib1, lib2);
}
private int compareName(ContributedLibrary lib1, ContributedLibrary lib2) {
return lib1.getName().compareToIgnoreCase(lib2.getName());
}
}

View File

@ -204,7 +204,7 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
contributions.clear();
indexer.getIndex().getLibraries().forEach(this::applyFilterToLibrary);
indexer.getInstalledLibraries().forEach(this::applyFilterToLibrary);
Collections.sort(contributions, new ContributedLibraryReleasesComparator());
Collections.sort(contributions, new ContributedLibraryReleasesComparator("Arduino"));
}
}