mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-17 06:52:18 +01:00
Dropping Guava predicates in favour of java.util.function.Predicate
This commit is contained in:
parent
ad1062455d
commit
dae6e4fff7
@ -35,7 +35,6 @@ import cc.arduino.contributions.packages.ContributedPackage;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.view.Event;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -48,6 +47,7 @@ import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -80,7 +80,7 @@ public class BuiltInCoreIsNewerCheck implements Runnable {
|
||||
}
|
||||
})));
|
||||
|
||||
List<ContributedPlatform> installedBuiltInPlatforms = new LinkedList<ContributedPlatform>(Collections2.filter(contributedPlatforms, Predicates.and(new InstalledPredicate(), new BuiltInPredicate())));
|
||||
List<ContributedPlatform> installedBuiltInPlatforms = contributedPlatforms.stream().filter(new InstalledPredicate()).filter(new BuiltInPredicate()).collect(Collectors.toList());
|
||||
if (installedBuiltInPlatforms.size() != 1) {
|
||||
return;
|
||||
}
|
||||
|
@ -29,12 +29,12 @@
|
||||
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class NoopPredicate<T> implements Predicate<T> {
|
||||
|
||||
@Override
|
||||
public boolean apply(T input) {
|
||||
public boolean test(T input) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,8 @@
|
||||
package cc.arduino.contributions.libraries.filters;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CategoryPredicate implements Predicate<ContributedLibrary> {
|
||||
|
||||
@ -41,7 +42,7 @@ public class CategoryPredicate implements Predicate<ContributedLibrary> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary input) {
|
||||
public boolean test(ContributedLibrary input) {
|
||||
return input.getCategory() != null && category.equals(input.getCategory());
|
||||
}
|
||||
|
||||
|
@ -32,10 +32,9 @@ package cc.arduino.contributions.libraries.filters;
|
||||
import cc.arduino.contributions.filters.InstalledPredicate;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndex;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class InstalledLibraryPredicate implements Predicate<ContributedLibrary> {
|
||||
|
||||
@ -46,14 +45,15 @@ public class InstalledLibraryPredicate implements Predicate<ContributedLibrary>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary input) {
|
||||
public boolean test(ContributedLibrary input) {
|
||||
if (input.isInstalled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Collection<ContributedLibrary> installed = Collections2.filter(index.find(input.getName()), new InstalledPredicate());
|
||||
|
||||
return !installed.isEmpty();
|
||||
List<ContributedLibrary> libraries = index.find(input.getName());
|
||||
return libraries.stream()
|
||||
.filter(new InstalledPredicate())
|
||||
.count() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,13 +30,14 @@
|
||||
package cc.arduino.contributions.libraries.filters;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import com.google.common.base.Predicate;
|
||||
import processing.app.packages.UserLibrary;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class OnlyUpstreamReleasePredicate implements Predicate<ContributedLibrary> {
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary input) {
|
||||
public boolean test(ContributedLibrary input) {
|
||||
return !(input instanceof UserLibrary);
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,10 @@ package cc.arduino.contributions.libraries.filters;
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndexer;
|
||||
import com.google.common.base.Predicate;
|
||||
import processing.app.packages.UserLibrary;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class UpdatableLibraryPredicate implements Predicate<ContributedLibrary> {
|
||||
|
||||
@ -19,7 +19,7 @@ public class UpdatableLibraryPredicate implements Predicate<ContributedLibrary>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary contributedLibrary) {
|
||||
public boolean test(ContributedLibrary contributedLibrary) {
|
||||
String libraryName = contributedLibrary.getName();
|
||||
UserLibrary installed = indexer.getInstalledLibraries().getByName(libraryName);
|
||||
if (installed == null) {
|
||||
|
@ -40,8 +40,6 @@ import cc.arduino.contributions.ui.InstallerTableCell;
|
||||
import cc.arduino.contributions.ui.listeners.DelegatingKeyListener;
|
||||
import cc.arduino.utils.ReverseComparator;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import processing.app.Base;
|
||||
|
||||
@ -58,8 +56,8 @@ import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import static processing.app.I18n.format;
|
||||
@ -248,10 +246,10 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
|
||||
final ContributedLibrary installed = editorValue.getInstalled();
|
||||
|
||||
List<ContributedLibrary> releases = new LinkedList<ContributedLibrary>(Collections2.filter(editorValue.releases, new OnlyUpstreamReleasePredicate()));
|
||||
List<ContributedLibrary> uninstalledReleases = new LinkedList<ContributedLibrary>(Collections2.filter(releases, Predicates.not(new InstalledPredicate())));
|
||||
List<ContributedLibrary> releases = editorValue.releases.stream().filter(new OnlyUpstreamReleasePredicate()).collect(Collectors.toList());
|
||||
List<ContributedLibrary> uninstalledReleases = releases.stream().filter(new InstalledPredicate().negate()).collect(Collectors.toList());
|
||||
|
||||
List<ContributedLibrary> installedBuiltIn = new LinkedList<ContributedLibrary>(Collections2.filter(releases, Predicates.and(new InstalledPredicate(), new BuiltInPredicate())));
|
||||
List<ContributedLibrary> installedBuiltIn = releases.stream().filter(new InstalledPredicate()).filter(new BuiltInPredicate()).collect(Collectors.toList());
|
||||
|
||||
if (installed != null && !installedBuiltIn.contains(installed)) {
|
||||
uninstalledReleases.addAll(installedBuiltIn);
|
||||
|
@ -33,7 +33,8 @@ import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndex;
|
||||
import cc.arduino.contributions.libraries.filters.InstalledLibraryPredicate;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
@ -32,7 +32,8 @@ package cc.arduino.contributions.libraries.ui;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.filters.CategoryPredicate;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DropdownLibraryOfCategoryItem implements DropdownItem<ContributedLibrary> {
|
||||
|
||||
|
@ -32,7 +32,8 @@ package cc.arduino.contributions.libraries.ui;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.filters.TypePredicate;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DropdownLibraryOfTypeItem implements DropdownItem<ContributedLibrary> {
|
||||
|
||||
|
@ -4,7 +4,8 @@ import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndexer;
|
||||
import cc.arduino.contributions.libraries.filters.UpdatableLibraryPredicate;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
@ -35,14 +35,14 @@ import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndexer;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class LibrariesIndexTableModel extends FilteredAbstractTableModel<ContributedLibrary> {
|
||||
@ -79,7 +79,7 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
||||
}
|
||||
|
||||
public ContributedLibrary getInstalled() {
|
||||
List<ContributedLibrary> installedReleases = new LinkedList<ContributedLibrary>(Collections2.filter(releases, new InstalledPredicate()));
|
||||
List<ContributedLibrary> installedReleases = releases.stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
Collections.sort(installedReleases, new DownloadableContributionBuiltInAtTheBottomComparator());
|
||||
|
||||
if (installedReleases.isEmpty()) {
|
||||
@ -127,8 +127,8 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
||||
Predicate<ContributedLibrary> selectedCategoryFilter = null;
|
||||
String selectedFilters[] = null;
|
||||
|
||||
public void updateIndexFilter(String filters[], Predicate<ContributedLibrary>... additionalFilters) {
|
||||
selectedCategoryFilter = Predicates.and(additionalFilters);
|
||||
public void updateIndexFilter(String filters[], Stream<Predicate<ContributedLibrary>> additionalFilters) {
|
||||
selectedCategoryFilter = additionalFilters.reduce(Predicate::and).get();
|
||||
selectedFilters = filters;
|
||||
update();
|
||||
}
|
||||
@ -229,7 +229,7 @@ public class LibrariesIndexTableModel extends FilteredAbstractTableModel<Contrib
|
||||
}
|
||||
|
||||
private void applyFilterToLibrary(ContributedLibrary lib) {
|
||||
if (selectedCategoryFilter != null && !selectedCategoryFilter.apply(lib)) {
|
||||
if (selectedCategoryFilter != null && !selectedCategoryFilter.test(lib)) {
|
||||
return;
|
||||
}
|
||||
if (!stringContainsAll(lib.getName(), selectedFilters) && !stringContainsAll(lib.getParagraph(), selectedFilters) && !stringContainsAll(lib.getSentence(), selectedFilters)) {
|
||||
|
@ -36,7 +36,6 @@ import cc.arduino.contributions.libraries.LibraryInstaller;
|
||||
import cc.arduino.contributions.libraries.LibraryTypeComparator;
|
||||
import cc.arduino.contributions.ui.*;
|
||||
import cc.arduino.utils.Progress;
|
||||
import com.google.common.base.Predicate;
|
||||
import processing.app.Platform;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -46,6 +45,7 @@ import java.awt.event.ActionListener;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
@ -30,7 +30,8 @@
|
||||
package cc.arduino.contributions.packages.filters;
|
||||
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class CategoryPredicate implements Predicate<ContributedPlatform> {
|
||||
|
||||
@ -41,7 +42,7 @@ public class CategoryPredicate implements Predicate<ContributedPlatform> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedPlatform input) {
|
||||
public boolean test(ContributedPlatform input) {
|
||||
return input.getCategory() != null && category.equals(input.getCategory());
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,9 @@ package cc.arduino.contributions.packages.filters;
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class UpdatablePlatformPredicate implements Predicate<ContributedPlatform> {
|
||||
|
||||
@ -18,7 +18,7 @@ public class UpdatablePlatformPredicate implements Predicate<ContributedPlatform
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedPlatform contributedPlatform) {
|
||||
public boolean test(ContributedPlatform contributedPlatform) {
|
||||
String packageName = contributedPlatform.getParentPackage().getName();
|
||||
String architecture = contributedPlatform.getArchitecture();
|
||||
|
||||
|
@ -41,8 +41,6 @@ import cc.arduino.contributions.ui.InstallerTableCell;
|
||||
import cc.arduino.contributions.ui.listeners.DelegatingKeyListener;
|
||||
import cc.arduino.utils.ReverseComparator;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import processing.app.Base;
|
||||
|
||||
@ -60,6 +58,7 @@ import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import static processing.app.I18n.format;
|
||||
@ -265,9 +264,9 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
||||
final ContributedPlatform installed = editorValue.getInstalled();
|
||||
|
||||
java.util.List<ContributedPlatform> releases = new LinkedList<ContributedPlatform>(editorValue.releases);
|
||||
java.util.List<ContributedPlatform> uninstalledReleases = new LinkedList<ContributedPlatform>(Collections2.filter(releases, Predicates.not(new InstalledPredicate())));
|
||||
java.util.List<ContributedPlatform> uninstalledReleases = releases.stream().filter(new InstalledPredicate().negate()).collect(Collectors.toList());
|
||||
|
||||
java.util.List<ContributedPlatform> installedBuiltIn = new LinkedList<ContributedPlatform>(Collections2.filter(releases, Predicates.and(new InstalledPredicate(), new BuiltInPredicate())));
|
||||
java.util.List<ContributedPlatform> installedBuiltIn = releases.stream().filter(new InstalledPredicate()).filter(new BuiltInPredicate()).collect(Collectors.toList());
|
||||
|
||||
if (installed != null && !installedBuiltIn.contains(installed)) {
|
||||
uninstalledReleases.addAll(installedBuiltIn);
|
||||
|
@ -35,14 +35,14 @@ import cc.arduino.contributions.packages.ContributedPackage;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import cc.arduino.contributions.ui.FilteredAbstractTableModel;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ContributionIndexTableModel extends FilteredAbstractTableModel<ContributedPlatform> {
|
||||
@ -80,7 +80,7 @@ public class ContributionIndexTableModel extends FilteredAbstractTableModel<Cont
|
||||
}
|
||||
|
||||
public ContributedPlatform getInstalled() {
|
||||
List<ContributedPlatform> installedReleases = new LinkedList<ContributedPlatform>(Collections2.filter(releases, new InstalledPredicate()));
|
||||
List<ContributedPlatform> installedReleases = releases.stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
Collections.sort(installedReleases, new DownloadableContributionBuiltInAtTheBottomComparator());
|
||||
|
||||
if (installedReleases.isEmpty()) {
|
||||
@ -120,12 +120,12 @@ public class ContributionIndexTableModel extends FilteredAbstractTableModel<Cont
|
||||
this.indexer = indexer;
|
||||
}
|
||||
|
||||
public void updateIndexFilter(String filters[], Predicate<ContributedPlatform>... additionalFilters) {
|
||||
public void updateIndexFilter(String filters[], Stream<Predicate<ContributedPlatform>> additionalFilters) {
|
||||
contributions.clear();
|
||||
Predicate<ContributedPlatform> filter = Predicates.and(additionalFilters);
|
||||
Predicate<ContributedPlatform> filter = additionalFilters.reduce(Predicate::and).get();
|
||||
for (ContributedPackage pack : indexer.getPackages()) {
|
||||
for (ContributedPlatform platform : pack.getPlatforms()) {
|
||||
if (!filter.apply(platform)) {
|
||||
if (!filter.test(platform)) {
|
||||
continue;
|
||||
}
|
||||
if (!stringContainsAll(platform.getName(), filters))
|
||||
|
@ -32,7 +32,8 @@ package cc.arduino.contributions.packages.ui;
|
||||
import cc.arduino.contributions.filters.NoopPredicate;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
@ -32,7 +32,8 @@ package cc.arduino.contributions.packages.ui;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.packages.filters.CategoryPredicate;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DropdownCoreOfCategoryItem implements DropdownItem<ContributedPlatform> {
|
||||
|
||||
|
@ -4,7 +4,8 @@ import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import cc.arduino.contributions.packages.filters.UpdatablePlatformPredicate;
|
||||
import cc.arduino.contributions.ui.DropdownItem;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
@ -31,7 +31,8 @@ package cc.arduino.contributions.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.filters.NoopPredicate;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
package cc.arduino.contributions.ui;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface DropdownItem<T> {
|
||||
|
||||
|
@ -31,17 +31,18 @@ package cc.arduino.contributions.ui;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class FilteredAbstractTableModel<T> extends AbstractTableModel {
|
||||
|
||||
abstract public void updateIndexFilter(String[] filters, Predicate<T>... additionalFilters);
|
||||
abstract public void updateIndexFilter(String[] filters, Stream<Predicate<T>> additionalFilters);
|
||||
|
||||
protected static <T extends DownloadableContribution> T getLatestOf(List<T> contribs) {
|
||||
contribs = new LinkedList<T>(contribs);
|
||||
|
@ -30,9 +30,6 @@
|
||||
package cc.arduino.contributions.ui;
|
||||
|
||||
import cc.arduino.contributions.ui.listeners.AbstractKeyListener;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import processing.app.Base;
|
||||
import processing.app.Theme;
|
||||
|
||||
@ -42,8 +39,8 @@ import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static cc.arduino.contributions.packages.ui.ContributionIndexTableModel.DESCRIPTION_COL;
|
||||
import static processing.app.I18n._;
|
||||
@ -241,8 +238,8 @@ public abstract class InstallerJDialog<T> extends JDialog {
|
||||
}
|
||||
|
||||
public void updateIndexFilter(String[] filters, Predicate<T>... additionalFilters) {
|
||||
Collection<Predicate<T>> notNullAdditionalFilters = Collections2.filter(Arrays.asList(additionalFilters), Predicates.notNull());
|
||||
contribModel.updateIndexFilter(filters, notNullAdditionalFilters.toArray(new Predicate[notNullAdditionalFilters.size()]));
|
||||
Stream<Predicate<T>> notNullAdditionalFilters = Stream.of(additionalFilters).filter(filter -> filter != null);
|
||||
contribModel.updateIndexFilter(filters, notNullAdditionalFilters);
|
||||
}
|
||||
|
||||
public void setErrorMessage(String message) {
|
||||
|
@ -30,12 +30,13 @@
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class BuiltInPredicate implements Predicate<DownloadableContribution> {
|
||||
|
||||
@Override
|
||||
public boolean apply(DownloadableContribution input) {
|
||||
public boolean test(DownloadableContribution input) {
|
||||
return input.isReadOnly();
|
||||
}
|
||||
|
||||
|
@ -30,11 +30,13 @@
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class InstalledPredicate implements Predicate<DownloadableContribution> {
|
||||
|
||||
@Override
|
||||
public boolean apply(DownloadableContribution input) {
|
||||
public boolean test(DownloadableContribution input) {
|
||||
return input.isInstalled();
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ import cc.arduino.contributions.libraries.filters.LibraryWithNamePredicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class LibrariesIndex {
|
||||
|
||||
@ -92,7 +93,7 @@ public abstract class LibrariesIndex {
|
||||
}
|
||||
|
||||
public ContributedLibrary getInstalled(String name) {
|
||||
List<ContributedLibrary> installedReleases = new LinkedList<ContributedLibrary>(Collections2.filter(find(name), new InstalledPredicate()));
|
||||
List<ContributedLibrary> installedReleases = find(name).stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
Collections.sort(installedReleases, new DownloadableContributionBuiltInAtTheBottomComparator());
|
||||
|
||||
if (installedReleases.isEmpty()) {
|
||||
|
@ -36,8 +36,6 @@ import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
@ -119,14 +117,10 @@ public class LibrariesIndexer {
|
||||
scanInstalledLibraries(folder, folder.equals(sketchbookLibrariesFolder));
|
||||
}
|
||||
|
||||
FluentIterable.from(installedLibraries).filter(new TypePredicate("Contributed")).filter(new LibraryInstalledInsideCore(contributionsIndexer)).transform(new Function<UserLibrary, Object>() {
|
||||
@Override
|
||||
public Object apply(UserLibrary userLibrary) {
|
||||
ContributedPlatform platform = contributionsIndexer.getPlatformByFolder(userLibrary.getInstalledFolder());
|
||||
userLibrary.setTypes(Collections.singletonList(platform.getCategory()));
|
||||
return userLibrary;
|
||||
}
|
||||
}).toList();
|
||||
installedLibraries.stream().filter(new TypePredicate("Contributed")).filter(new LibraryInstalledInsideCore(contributionsIndexer)).forEach(userLibrary -> {
|
||||
ContributedPlatform platform = contributionsIndexer.getPlatformByFolder(userLibrary.getInstalledFolder());
|
||||
userLibrary.setTypes(Collections.singletonList(platform.getCategory()));
|
||||
});
|
||||
}
|
||||
|
||||
private void scanInstalledLibraries(File folder, boolean isSketchbook) {
|
||||
|
@ -31,7 +31,8 @@ package cc.arduino.contributions.libraries.filters;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class LibraryInstalledInsideCore implements Predicate<ContributedLibrary> {
|
||||
|
||||
@ -42,7 +43,7 @@ public class LibraryInstalledInsideCore implements Predicate<ContributedLibrary>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary contributedLibrary) {
|
||||
public boolean test(ContributedLibrary contributedLibrary) {
|
||||
return indexer.isFolderInsidePlatform(contributedLibrary.getInstalledFolder());
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,8 @@
|
||||
package cc.arduino.contributions.libraries.filters;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class TypePredicate implements Predicate<ContributedLibrary> {
|
||||
|
||||
@ -41,7 +42,7 @@ public class TypePredicate implements Predicate<ContributedLibrary> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary input) {
|
||||
public boolean test(ContributedLibrary input) {
|
||||
return input.getTypes() != null && input.getTypes().contains(type);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,11 @@ import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public abstract class ContributionsIndex {
|
||||
|
||||
@ -84,7 +88,7 @@ public abstract class ContributionsIndex {
|
||||
}
|
||||
|
||||
public List<ContributedPlatform> getInstalledPlatforms() {
|
||||
return Lists.newLinkedList(Collections2.filter(getPlatforms(), new InstalledPredicate()));
|
||||
return getPlatforms().stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ContributedPlatform getInstalledPlatform(String packageName, String platformArch) {
|
||||
@ -92,7 +96,7 @@ public abstract class ContributionsIndex {
|
||||
if (platforms == null) {
|
||||
return null;
|
||||
}
|
||||
List<ContributedPlatform> installedPlatforms = new LinkedList<>(Collections2.filter(platforms, new InstalledPredicate()));
|
||||
List<ContributedPlatform> installedPlatforms = platforms.stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
Collections.sort(installedPlatforms, new DownloadableContributionBuiltInAtTheBottomComparator());
|
||||
|
||||
if (installedPlatforms.isEmpty()) {
|
||||
|
@ -37,7 +37,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import com.google.common.collect.Iterables;
|
||||
@ -57,6 +56,7 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import static processing.app.helpers.filefilters.OnlyDirs.ONLY_DIRS;
|
||||
@ -304,7 +304,7 @@ public class ContributionsIndexer {
|
||||
for (ContributedPackage aPackage : index.getPackages()) {
|
||||
ContributedTargetPackage targetPackage = new ContributedTargetPackage(aPackage.getName());
|
||||
|
||||
List<ContributedPlatform> platforms = new LinkedList<ContributedPlatform>(Collections2.filter(aPackage.getPlatforms(), new InstalledPredicate()));
|
||||
List<ContributedPlatform> platforms = aPackage.getPlatforms().stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
Collections.sort(platforms, new DownloadableContributionBuiltInAtTheBottomComparator());
|
||||
|
||||
for (ContributedPlatform platform : platforms) {
|
||||
@ -363,7 +363,7 @@ public class ContributionsIndexer {
|
||||
return tools;
|
||||
}
|
||||
for (ContributedPackage pack : index.getPackages()) {
|
||||
Collection<ContributedPlatform> platforms = Collections2.filter(pack.getPlatforms(), new InstalledPredicate());
|
||||
Collection<ContributedPlatform> platforms = pack.getPlatforms().stream().filter(new InstalledPredicate()).collect(Collectors.toList());
|
||||
ImmutableListMultimap<String, ContributedPlatform> platformsByName = Multimaps.index(platforms, new Function<ContributedPlatform, String>() {
|
||||
@Override
|
||||
public String apply(ContributedPlatform contributedPlatform) {
|
||||
@ -374,7 +374,7 @@ public class ContributionsIndexer {
|
||||
for (Map.Entry<String, Collection<ContributedPlatform>> entry : platformsByName.asMap().entrySet()) {
|
||||
Collection<ContributedPlatform> platformsWithName = entry.getValue();
|
||||
if (platformsWithName.size() > 1) {
|
||||
platformsWithName = Collections2.filter(platformsWithName, Predicates.not(new BuiltInPredicate()));
|
||||
platformsWithName = platformsWithName.stream().filter(new BuiltInPredicate().negate()).collect(Collectors.toList());
|
||||
}
|
||||
for (ContributedPlatform platform : platformsWithName) {
|
||||
tools.addAll(platform.getResolvedTools());
|
||||
|
Loading…
x
Reference in New Issue
Block a user