mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 12:05:14 +01:00
Add docs for ContentFilter class.
This commit is contained in:
parent
ddcd325c21
commit
1c1245a711
@ -9,7 +9,11 @@ import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
/**
|
||||
* Filter content and text based on regex.
|
||||
* <p>Filter content and text based on regex matching.</p>
|
||||
*
|
||||
* <p>Compile regex pattern based on {@link ContentFilter#filterString}. When prefixed with 'r=',
|
||||
* use {@link ContentFilter#filterString} as the full regex pattern. Else, set to any match that
|
||||
* contains the {@link ContentFilter#filterString}.<p>
|
||||
*/
|
||||
public class ContentFilter {
|
||||
|
||||
@ -20,13 +24,20 @@ public class ContentFilter {
|
||||
private Pattern filterPattern;
|
||||
private boolean exactMatch;
|
||||
|
||||
public ContentFilter() {
|
||||
private ContentFilter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filterString The text to do matching, either plaintext or regex.
|
||||
*/
|
||||
public ContentFilter(@NotNull String filterString) {
|
||||
this(filterString, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filterString The text to do matching, else plaintext or regex.
|
||||
* @param exactMatch Should check for exact match when doing regex matching.
|
||||
*/
|
||||
public ContentFilter(@NotNull String filterString,
|
||||
boolean exactMatch) {
|
||||
|
||||
@ -35,11 +46,6 @@ public class ContentFilter {
|
||||
parseFilter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile regex pattern based on {@link ContentFilter#filterString}.
|
||||
* When prefixed with 'r=', use {@link ContentFilter#filterString} as the full regex pattern.
|
||||
* Else, set to any match that contains the {@link ContentFilter#filterString}.
|
||||
*/
|
||||
private void parseFilter() {
|
||||
if (filterString == null) {
|
||||
return;
|
||||
@ -54,6 +60,8 @@ public class ContentFilter {
|
||||
|
||||
/**
|
||||
* Compile and store the regex into a {@link Pattern}.
|
||||
*
|
||||
* @param regex The regex text.
|
||||
*/
|
||||
private void convertToMatcher(@NotNull String regex) {
|
||||
try {
|
||||
@ -84,22 +92,43 @@ public class ContentFilter {
|
||||
: filterPattern.matcher((CharSequence) text).find();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a filter string is present.
|
||||
*
|
||||
* @return True if there is a filter string, else false.
|
||||
*/
|
||||
public boolean hasFilter() {
|
||||
return filterString != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if regex pattern syntax is valid.
|
||||
*
|
||||
* @return True if valid, else false.
|
||||
*/
|
||||
public boolean hasValidPattern() {
|
||||
return filterPattern != null;
|
||||
}
|
||||
|
||||
public @Nullable String getString() {
|
||||
/**
|
||||
* @return The filter string.
|
||||
*/
|
||||
@Nullable
|
||||
public String getString() {
|
||||
return filterString;
|
||||
}
|
||||
|
||||
public @Nullable Pattern getPattern() {
|
||||
/**
|
||||
* @return The regex pattern.
|
||||
*/
|
||||
@Nullable
|
||||
public Pattern getPattern() {
|
||||
return filterPattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return True if filter is set to do exact matching, else false.
|
||||
*/
|
||||
public boolean isExactMatch() {
|
||||
return exactMatch;
|
||||
}
|
||||
@ -107,7 +136,7 @@ public class ContentFilter {
|
||||
/**
|
||||
* Nicely format the filter string to be used for showing the sender.
|
||||
*
|
||||
* @return formatted filter string.
|
||||
* @return The formatted filter string.
|
||||
*/
|
||||
public @NotNull String getFormattedString() {
|
||||
return String.format("%sFilter: '%s'%s", ChatColor.ITALIC, filterString, ChatColor.RESET);
|
||||
|
Loading…
Reference in New Issue
Block a user