From 98aa9fb7d79e48169b39472c8115ad21dec303d4 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Thu, 27 Feb 2020 05:28:07 +0100 Subject: [PATCH] Move matchesSearchTerms util to Text class Signed-off-by: Tomas Slusny --- .../ExternalPluginManifest.java | 3 +++ .../client/plugins/config/PluginListItem.java | 22 +------------------ .../plugins/config/PluginListPanel.java | 2 +- .../java/net/runelite/client/util/Text.java | 20 +++++++++++++++++ 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/externalplugins/ExternalPluginManifest.java b/runelite-client/src/main/java/net/runelite/client/externalplugins/ExternalPluginManifest.java index 95b5fe5637..0678bf768c 100644 --- a/runelite-client/src/main/java/net/runelite/client/externalplugins/ExternalPluginManifest.java +++ b/runelite-client/src/main/java/net/runelite/client/externalplugins/ExternalPluginManifest.java @@ -29,6 +29,7 @@ import com.google.common.io.Files; import java.io.File; import java.io.IOException; import java.net.URL; +import javax.annotation.Nullable; import lombok.Data; import lombok.EqualsAndHashCode; import net.runelite.client.RuneLite; @@ -45,7 +46,9 @@ public class ExternalPluginManifest private String displayName; private String version; private String author; + @Nullable private String description; + @Nullable private String[] tags; @EqualsAndHashCode.Exclude private URL support; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListItem.java b/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListItem.java index 9b1575acc3..2c5cfe5bbd 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListItem.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListItem.java @@ -52,12 +52,9 @@ import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.PluginPanel; import net.runelite.client.util.ImageUtil; import net.runelite.client.util.SwingUtil; -import org.apache.commons.text.similarity.JaroWinklerDistance; class PluginListItem extends JPanel { - private static final JaroWinklerDistance DISTANCE = new JaroWinklerDistance(); - private static final ImageIcon CONFIG_ICON; private static final ImageIcon CONFIG_ICON_HOVER; private static final ImageIcon ON_STAR; @@ -68,6 +65,7 @@ class PluginListItem extends JPanel @Getter private final PluginConfigurationDescriptor pluginConfig; + @Getter private final List keywords = new ArrayList<>(); private final JToggleButton pinButton; @@ -202,24 +200,6 @@ class PluginListItem extends JPanel onOffToggle.setSelected(enabled); } - /** - * Checks if all the search terms in the given list matches at least one keyword. - * - * @return true if all search terms matches at least one keyword, or false if otherwise. - */ - boolean matchesSearchTerms(String[] searchTerms) - { - for (String term : searchTerms) - { - if (keywords.stream().noneMatch((t) -> t.contains(term) || - DISTANCE.apply(t, term) > 0.9)) - { - return false; - } - } - return true; - } - private void openGroupConfigPanel() { pluginListPanel.openConfigurationPanel(pluginConfig); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListPanel.java index 2e96a4dae9..57ac970cae 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/config/PluginListPanel.java @@ -271,7 +271,7 @@ class PluginListPanel extends PluginPanel final String[] searchTerms = text.toLowerCase().split(" "); pluginList.forEach(listItem -> { - if (pinned == listItem.isPinned() && listItem.matchesSearchTerms(searchTerms)) + if (pinned == listItem.isPinned() && Text.matchesSearchTerms(searchTerms, listItem.getKeywords())) { mainPanel.add(listItem); } diff --git a/runelite-client/src/main/java/net/runelite/client/util/Text.java b/runelite-client/src/main/java/net/runelite/client/util/Text.java index 78c08f16aa..6fc303a97e 100644 --- a/runelite-client/src/main/java/net/runelite/client/util/Text.java +++ b/runelite-client/src/main/java/net/runelite/client/util/Text.java @@ -32,12 +32,14 @@ import java.util.Collection; import java.util.List; import java.util.regex.Pattern; import org.apache.commons.text.WordUtils; +import org.apache.commons.text.similarity.JaroWinklerDistance; /** * A set of utilities to use when dealing with text. */ public class Text { + private static final JaroWinklerDistance DISTANCE = new JaroWinklerDistance(); private static final Pattern TAG_REGEXP = Pattern.compile("<[^>]*>"); private static final Splitter COMMA_SPLITTER = Splitter .on(",") @@ -186,4 +188,22 @@ public class Text return toString; } + + /** + * Checks if all the search terms in the given list matches at least one keyword. + * + * @return true if all search terms matches at least one keyword, or false if otherwise. + */ + public static boolean matchesSearchTerms(String[] searchTerms, final Collection keywords) + { + for (String term : searchTerms) + { + if (keywords.stream().noneMatch((t) -> t.contains(term) || + DISTANCE.apply(t, term) > 0.9)) + { + return false; + } + } + return true; + } }