Move matchesSearchTerms util to Text class

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2020-02-27 05:28:07 +01:00
committed by loldudester
parent 20920be0c0
commit 98aa9fb7d7
4 changed files with 25 additions and 22 deletions

View File

@@ -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;

View File

@@ -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<String> 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);

View File

@@ -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);
}

View File

@@ -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<String> keywords)
{
for (String term : searchTerms)
{
if (keywords.stream().noneMatch((t) -> t.contains(term) ||
DISTANCE.apply(t, term) > 0.9))
{
return false;
}
}
return true;
}
}