Few impros for performance in itempool countAll

This implementation leverages on iterables.filter to filter all keys matching the input condition, which will be iterated for counting.
This commit is contained in:
leriomaggio
2021-08-27 20:05:12 +01:00
parent 7a7b23e593
commit b413b777bf
2 changed files with 15 additions and 9 deletions

View File

@@ -1,6 +1,7 @@
package forge.itemmanager.filters;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.swing.JPanel;
@@ -76,10 +77,12 @@ public abstract class StatTypeFilter<T extends InventoryItem> extends ToggleButt
btnPackOrDeck.setText(String.valueOf(count));
}
for (Map.Entry<StatTypes, FLabel> btn : buttonMap.entrySet()) {
if (btn.getKey().predicate != null) {
int count = items.countAll(Predicates.compose(btn.getKey().predicate, PaperCard.FN_GET_RULES), PaperCard.class);
btn.getValue().setText(String.valueOf(count));
Iterator<StatTypes> buttonMapStatsIterator = buttonMap.keySet().iterator();
while (buttonMapStatsIterator.hasNext()){
StatTypes statTypes = buttonMapStatsIterator.next();
if (statTypes.predicate != null){
int count = items.countAll(Predicates.compose(statTypes.predicate, PaperCard.FN_GET_RULES), PaperCard.class);
buttonMap.get(statTypes).setText(String.valueOf(count));
}
}
getWidget().revalidate();