From 92f55c588a9f3bd4ae0e345767dbc053c9773a37 Mon Sep 17 00:00:00 2001 From: GoldenGnu Date: Wed, 30 Oct 2024 19:21:47 +0100 Subject: [PATCH] Code: Optimization of FilterMatcher (Optional, on by default) --- .../java/net/nikr/eve/jeveasset/Program.java | 2 + .../eve/jeveasset/data/settings/Settings.java | 20 +++++-- .../settings/ExperimentalSettingsPanel.java | 60 +++++++++++++++++++ .../gui/dialogs/settings/SettingsDialog.java | 2 + .../gui/shared/filter/FilterMatcher.java | 24 ++++++++ 5 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/ExperimentalSettingsPanel.java diff --git a/src/main/java/net/nikr/eve/jeveasset/Program.java b/src/main/java/net/nikr/eve/jeveasset/Program.java index 4a4e42f52..1779105c8 100644 --- a/src/main/java/net/nikr/eve/jeveasset/Program.java +++ b/src/main/java/net/nikr/eve/jeveasset/Program.java @@ -83,6 +83,7 @@ import net.nikr.eve.jeveasset.gui.shared.components.JLockWindow; import net.nikr.eve.jeveasset.gui.shared.components.JLockWindow.LockWorkerAdaptor; import net.nikr.eve.jeveasset.gui.shared.components.JMainTab; +import net.nikr.eve.jeveasset.gui.shared.filter.FilterMatcher; import net.nikr.eve.jeveasset.gui.sounds.SoundPlayer; import net.nikr.eve.jeveasset.gui.tabs.assets.AssetsTab; import net.nikr.eve.jeveasset.gui.tabs.contracts.ContractsTab; @@ -606,6 +607,7 @@ public final void updateEventLists() { private synchronized void updateEventLists(Set itemIDs, Set locationIDs, Set typeIDs, OutbidProcesserOutput output) { LOG.info("Updating EventList"); + FilterMatcher.clearColumnValueCache(); for (JMainTab jMainTab : mainWindow.getTabs()) { ensureEDT(new Runnable() { @Override diff --git a/src/main/java/net/nikr/eve/jeveasset/data/settings/Settings.java b/src/main/java/net/nikr/eve/jeveasset/data/settings/Settings.java index b90097810..1141bd380 100644 --- a/src/main/java/net/nikr/eve/jeveasset/data/settings/Settings.java +++ b/src/main/java/net/nikr/eve/jeveasset/data/settings/Settings.java @@ -106,7 +106,8 @@ public static enum SettingFlag { FLAG_SHOW_SUBPILE_TREE, FLAG_INDUSTRY_JOBS_HISTORY, FLAG_ASSETS_CONTRACTS_OWNER_CORP, - FLAG_ASSETS_CONTRACTS_OWNER_BOTH + FLAG_ASSETS_CONTRACTS_OWNER_BOTH, + FLAG_CELL_VALUE_CACHE } public static enum TransactionProfitPrice { @@ -231,7 +232,8 @@ public String toString() { private Boolean highlightSelectedRows = null; //Assets private Boolean reprocessColors = null; //Assets private Boolean stockpileHalfColors = null; //Stockpile - private Boolean containersShowItemID = null; //Stockpile + private Boolean containersShowItemID = null; //Container ItemID + private Boolean cellValueCache = null; //Cell value cache //Table settings //Filters Saved by ExportFilterControl.saveSettings() //Lock OK @@ -308,6 +310,7 @@ protected Settings() { flags.put(SettingFlag.FLAG_INDUSTRY_JOBS_HISTORY, true); flags.put(SettingFlag.FLAG_ASSETS_CONTRACTS_OWNER_CORP, false); flags.put(SettingFlag.FLAG_ASSETS_CONTRACTS_OWNER_BOTH, false); + flags.put(SettingFlag.FLAG_CELL_VALUE_CACHE, true); cacheFlags(); //Default Filters List filter; @@ -491,6 +494,7 @@ public final void cacheFlags() { reprocessColors = flags.get(SettingFlag.FLAG_REPROCESS_COLORS); stockpileHalfColors = flags.get(SettingFlag.FLAG_STOCKPILE_HALF_COLORS); containersShowItemID = flags.get(SettingFlag.FLAG_CONTAINERS_SHOW_ITEM_ID); + cellValueCache = flags.get(SettingFlag.FLAG_CELL_VALUE_CACHE); } public ReprocessSettings getReprocessSettings() { @@ -735,9 +739,6 @@ public void setTransactionProfitMargin(int transactionProfitMargin) { } public boolean isFilterOnEnter() { - if (filterOnEnter == null) { - filterOnEnter = flags.get(SettingFlag.FLAG_FILTER_ON_ENTER); - } return filterOnEnter; } @@ -934,6 +935,15 @@ public void setAssetsContractsOwnerBoth(final boolean assetsContractsOwnerBoth) flags.put(SettingFlag.FLAG_ASSETS_CONTRACTS_OWNER_BOTH, assetsContractsOwnerBoth); } + public boolean isColumnValueCache() { + return cellValueCache; + } + + public void setCellValueCache(final boolean cellValueCache) { + flags.put(SettingFlag.FLAG_CELL_VALUE_CACHE, cellValueCache); + this.cellValueCache = cellValueCache; + } + public boolean isMarketOrderHistory() { return flags.get(SettingFlag.FLAG_MARKET_ORDER_HISTORY); } diff --git a/src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/ExperimentalSettingsPanel.java b/src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/ExperimentalSettingsPanel.java new file mode 100644 index 000000000..fb13abb61 --- /dev/null +++ b/src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/ExperimentalSettingsPanel.java @@ -0,0 +1,60 @@ +/* + * Copyright 2009-2024 Contributors (see credits.txt) + * + * This file is part of jEveAssets. + * + * jEveAssets is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * jEveAssets is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with jEveAssets; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +package net.nikr.eve.jeveasset.gui.dialogs.settings; + +import javax.swing.GroupLayout; +import javax.swing.JCheckBox; +import net.nikr.eve.jeveasset.Program; +import net.nikr.eve.jeveasset.data.settings.Settings; +import net.nikr.eve.jeveasset.gui.images.Images; + + +public class ExperimentalSettingsPanel extends JSettingsPanel { + + private final JCheckBox jCellValueCache; + + public ExperimentalSettingsPanel(final Program program, final SettingsDialog settingsDialog) { + super(program, settingsDialog, "Experimental", Images.JOBS_INVENTION_SUCCESS.getIcon()); + jCellValueCache = new JCheckBox("Filter cell value cache"); + + layout.setHorizontalGroup( + layout.createParallelGroup(GroupLayout.Alignment.LEADING) + .addComponent(jCellValueCache) + ); + layout.setVerticalGroup( + layout.createSequentialGroup() + .addComponent(jCellValueCache, Program.getButtonsHeight(), Program.getButtonsHeight(), Program.getButtonsHeight()) + ); + } + + @Override + public UpdateType save() { + Settings.get().setCellValueCache(jCellValueCache.isSelected()); + return UpdateType.NONE; + } + + @Override + public void load() { + jCellValueCache.setSelected(Settings.get().isColumnValueCache()); + } + +} diff --git a/src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/SettingsDialog.java b/src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/SettingsDialog.java index 826bac8be..7a4b61924 100644 --- a/src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/SettingsDialog.java +++ b/src/main/java/net/nikr/eve/jeveasset/gui/dialogs/settings/SettingsDialog.java @@ -108,6 +108,8 @@ public SettingsDialog(final Program program) { GeneralSettingsPanel generalSettingsPanel = new GeneralSettingsPanel(program, this); add(generalSettingsPanel); + add(new ExperimentalSettingsPanel(program, this)); + DefaultMutableTreeNode toolNode = addGroup(DialoguesSettings.get().tools(), Images.SETTINGS_TOOLS.getIcon()); add(toolNode, new ShowToolSettingsPanel(program, this)); diff --git a/src/main/java/net/nikr/eve/jeveasset/gui/shared/filter/FilterMatcher.java b/src/main/java/net/nikr/eve/jeveasset/gui/shared/filter/FilterMatcher.java index 69f1987bb..1c2b95ae2 100644 --- a/src/main/java/net/nikr/eve/jeveasset/gui/shared/filter/FilterMatcher.java +++ b/src/main/java/net/nikr/eve/jeveasset/gui/shared/filter/FilterMatcher.java @@ -26,7 +26,9 @@ import java.text.ParsePosition; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; import java.util.TimeZone; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -46,6 +48,8 @@ public class FilterMatcher implements Matcher { private static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(LOCALE); private static final NumberFormat PERCENT_FORMAT = NumberFormat.getPercentInstance(LOCALE); private static final Calendar CALENDAR = Calendar.getInstance(TimeZone.getTimeZone("GMT")); + private static final Map CELL_VALUE_CACHE = new HashMap<>(); + private static boolean cellValueCache = false; //Cell value cache private final SimpleTableFormat tableFormat; private final ColumnCache columnCache; @@ -482,7 +486,27 @@ private static String formatData(final Object object, final boolean userInput) { return format(object, userInput).toLowerCase(); } + public static void clearColumnValueCache() { + CELL_VALUE_CACHE.clear(); + cellValueCache = Settings.get().isColumnValueCache(); + } + private static String format(final Object object, final boolean userInput) { + if (cellValueCache) { + String value = CELL_VALUE_CACHE.get(object); + if (value != null) { + return value; + } else { + value = createFormat(object, userInput); + CELL_VALUE_CACHE.put(object, value); + return value; + } + } else { + return createFormat(object, userInput); + } + } + + private static String createFormat(final Object object, final boolean userInput) { if (object == null) { return null; }