Skip to content

Commit 212825e

Browse files
committed
Simplified overly complex filtering of InstallerJDialog
- we ensure that there is always a filter selected, no more need to check for non-nullness - the filters are always the same, no need to pass a Stream<Predicate<T>> around where Predicate<T> suffices
1 parent f111905 commit 212825e

File tree

5 files changed

+9
-24
lines changed

5 files changed

+9
-24
lines changed

app/src/cc/arduino/contributions/libraries/ui/LibrariesIndexTableModel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import java.util.Collections;
3939
import java.util.List;
4040
import java.util.function.Predicate;
41-
import java.util.stream.Stream;
4241

4342
@SuppressWarnings("serial")
4443
public class LibrariesIndexTableModel
@@ -54,8 +53,8 @@ public class LibrariesIndexTableModel
5453
String selectedFilters[] = null;
5554

5655
public void updateIndexFilter(String filters[],
57-
Stream<Predicate<ContributedLibrary>> additionalFilters) {
58-
selectedCategoryFilter = additionalFilters.reduce(Predicate::and).get();
56+
Predicate<ContributedLibrary> additionalFilter) {
57+
selectedCategoryFilter = additionalFilter;
5958
selectedFilters = filters;
6059
update();
6160
}

app/src/cc/arduino/contributions/libraries/ui/LibraryManagerUI.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,16 @@ public LibraryManagerUI(Frame parent, LibraryInstaller installer) {
118118
public void actionPerformed(ActionEvent event) {
119119
DropdownItem<ContributedLibrary> selected = (DropdownItem<ContributedLibrary>) typeChooser.getSelectedItem();
120120
previousRowAtPoint = -1;
121-
if (typeFilter == null || typeFilter != selected.getFilterPredicate()) {
121+
if (selected != null && typeFilter != selected.getFilterPredicate()) {
122122
typeFilter = selected.getFilterPredicate();
123123
if (contribTable.getCellEditor() != null) {
124124
contribTable.getCellEditor().stopCellEditing();
125125
}
126-
updateIndexFilter(filters, categoryFilter, typeFilter);
126+
updateIndexFilter(filters, categoryFilter.and(typeFilter));
127127
}
128128
}
129129
};
130130

131-
@Override
132-
public void updateIndexFilter(String[] filters, Predicate<ContributedLibrary>... additionalFilters) {
133-
if (additionalFilters.length == 1) {
134-
additionalFilters = new Predicate[]{additionalFilters[0], typeFilter};
135-
}
136-
super.updateIndexFilter(filters, additionalFilters);
137-
}
138-
139131
public void updateUI() {
140132
DropdownItem<DownloadableContribution> previouslySelectedCategory = (DropdownItem<DownloadableContribution>) categoryChooser.getSelectedItem();
141133
DropdownItem<DownloadableContribution> previouslySelectedType = (DropdownItem<DownloadableContribution>) typeChooser.getSelectedItem();

app/src/cc/arduino/contributions/packages/ui/ContributionIndexTableModel.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.util.List;
4040
import java.util.function.Predicate;
4141
import java.util.stream.Collectors;
42-
import java.util.stream.Stream;
4342

4443
@SuppressWarnings("serial")
4544
public class ContributionIndexTableModel
@@ -50,10 +49,8 @@ public class ContributionIndexTableModel
5049
private final Class<?>[] columnTypes = { ContributedPlatform.class };
5150

5251
public void updateIndexFilter(String[] filters,
53-
Stream<Predicate<ContributedPlatform>> additionalFilters) {
52+
Predicate<ContributedPlatform> filter) {
5453
contributions.clear();
55-
Predicate<ContributedPlatform> filter = additionalFilters
56-
.reduce(Predicate::and).get();
5754
for (ContributedPackage pack : BaseNoGui.indexer.getPackages()) {
5855
for (ContributedPlatform platform : pack.getPlatforms()) {
5956
String compoundTargetSearchText = platform.getName() + "\n"

app/src/cc/arduino/contributions/ui/FilteredAbstractTableModel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@
3737
import java.util.LinkedList;
3838
import java.util.List;
3939
import java.util.function.Predicate;
40-
import java.util.stream.Stream;
4140

4241
public abstract class FilteredAbstractTableModel<T> extends AbstractTableModel {
4342

44-
abstract public void updateIndexFilter(String[] filters, Stream<Predicate<T>> additionalFilters);
43+
abstract public void updateIndexFilter(String[] filters, Predicate<T> additionalFilter);
4544

4645
public static <T extends DownloadableContribution> T getLatestOf(List<T> contribs) {
4746
contribs = new LinkedList<>(contribs);

app/src/cc/arduino/contributions/ui/InstallerJDialog.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.awt.event.MouseEvent;
4747
import java.awt.event.MouseMotionListener;
4848
import java.util.function.Predicate;
49-
import java.util.stream.Stream;
5049

5150
import javax.swing.Box;
5251
import javax.swing.BoxLayout;
@@ -265,9 +264,8 @@ public void mouseMoved(MouseEvent e) {
265264
SwingUtilities.invokeLater(InstallerJDialog.this::onUpdatePressed);
266265
}
267266

268-
public void updateIndexFilter(String[] filters, Predicate<T>... additionalFilters) {
269-
Stream<Predicate<T>> notNullAdditionalFilters = Stream.of(additionalFilters).filter(filter -> filter != null);
270-
contribModel.updateIndexFilter(filters, notNullAdditionalFilters);
267+
public void updateIndexFilter(String[] filters, Predicate<T> additionalFilter) {
268+
contribModel.updateIndexFilter(filters, additionalFilter);
271269
}
272270

273271
public void setErrorMessage(String message) {
@@ -311,7 +309,7 @@ private void setErrorMessageVisible(boolean visible) {
311309
public void actionPerformed(ActionEvent event) {
312310
DropdownItem<T> selected = (DropdownItem<T>) categoryChooser.getSelectedItem();
313311
previousRowAtPoint = -1;
314-
if (categoryFilter == null || categoryFilter != selected.getFilterPredicate()) {
312+
if (selected != null && categoryFilter != selected.getFilterPredicate()) {
315313
categoryFilter = selected.getFilterPredicate();
316314
if (contribTable.getCellEditor() != null) {
317315
contribTable.getCellEditor().stopCellEditing();

0 commit comments

Comments
 (0)