Move matchesSearchTerms util to Text class
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
committed by
loldudester
parent
20920be0c0
commit
98aa9fb7d7
@@ -29,6 +29,7 @@ import com.google.common.io.Files;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
@@ -45,7 +46,9 @@ public class ExternalPluginManifest
|
|||||||
private String displayName;
|
private String displayName;
|
||||||
private String version;
|
private String version;
|
||||||
private String author;
|
private String author;
|
||||||
|
@Nullable
|
||||||
private String description;
|
private String description;
|
||||||
|
@Nullable
|
||||||
private String[] tags;
|
private String[] tags;
|
||||||
@EqualsAndHashCode.Exclude
|
@EqualsAndHashCode.Exclude
|
||||||
private URL support;
|
private URL support;
|
||||||
|
|||||||
@@ -52,12 +52,9 @@ import net.runelite.client.ui.ColorScheme;
|
|||||||
import net.runelite.client.ui.PluginPanel;
|
import net.runelite.client.ui.PluginPanel;
|
||||||
import net.runelite.client.util.ImageUtil;
|
import net.runelite.client.util.ImageUtil;
|
||||||
import net.runelite.client.util.SwingUtil;
|
import net.runelite.client.util.SwingUtil;
|
||||||
import org.apache.commons.text.similarity.JaroWinklerDistance;
|
|
||||||
|
|
||||||
class PluginListItem extends JPanel
|
class PluginListItem extends JPanel
|
||||||
{
|
{
|
||||||
private static final JaroWinklerDistance DISTANCE = new JaroWinklerDistance();
|
|
||||||
|
|
||||||
private static final ImageIcon CONFIG_ICON;
|
private static final ImageIcon CONFIG_ICON;
|
||||||
private static final ImageIcon CONFIG_ICON_HOVER;
|
private static final ImageIcon CONFIG_ICON_HOVER;
|
||||||
private static final ImageIcon ON_STAR;
|
private static final ImageIcon ON_STAR;
|
||||||
@@ -68,6 +65,7 @@ class PluginListItem extends JPanel
|
|||||||
@Getter
|
@Getter
|
||||||
private final PluginConfigurationDescriptor pluginConfig;
|
private final PluginConfigurationDescriptor pluginConfig;
|
||||||
|
|
||||||
|
@Getter
|
||||||
private final List<String> keywords = new ArrayList<>();
|
private final List<String> keywords = new ArrayList<>();
|
||||||
|
|
||||||
private final JToggleButton pinButton;
|
private final JToggleButton pinButton;
|
||||||
@@ -202,24 +200,6 @@ class PluginListItem extends JPanel
|
|||||||
onOffToggle.setSelected(enabled);
|
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()
|
private void openGroupConfigPanel()
|
||||||
{
|
{
|
||||||
pluginListPanel.openConfigurationPanel(pluginConfig);
|
pluginListPanel.openConfigurationPanel(pluginConfig);
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ class PluginListPanel extends PluginPanel
|
|||||||
final String[] searchTerms = text.toLowerCase().split(" ");
|
final String[] searchTerms = text.toLowerCase().split(" ");
|
||||||
pluginList.forEach(listItem ->
|
pluginList.forEach(listItem ->
|
||||||
{
|
{
|
||||||
if (pinned == listItem.isPinned() && listItem.matchesSearchTerms(searchTerms))
|
if (pinned == listItem.isPinned() && Text.matchesSearchTerms(searchTerms, listItem.getKeywords()))
|
||||||
{
|
{
|
||||||
mainPanel.add(listItem);
|
mainPanel.add(listItem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,12 +32,14 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.apache.commons.text.WordUtils;
|
import org.apache.commons.text.WordUtils;
|
||||||
|
import org.apache.commons.text.similarity.JaroWinklerDistance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of utilities to use when dealing with text.
|
* A set of utilities to use when dealing with text.
|
||||||
*/
|
*/
|
||||||
public class Text
|
public class Text
|
||||||
{
|
{
|
||||||
|
private static final JaroWinklerDistance DISTANCE = new JaroWinklerDistance();
|
||||||
private static final Pattern TAG_REGEXP = Pattern.compile("<[^>]*>");
|
private static final Pattern TAG_REGEXP = Pattern.compile("<[^>]*>");
|
||||||
private static final Splitter COMMA_SPLITTER = Splitter
|
private static final Splitter COMMA_SPLITTER = Splitter
|
||||||
.on(",")
|
.on(",")
|
||||||
@@ -186,4 +188,22 @@ public class Text
|
|||||||
|
|
||||||
return toString;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user