Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LisoUseInAIKyrios committed Oct 3, 2023
1 parent e433cba commit 3177625
Showing 1 changed file with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@
abstract class FilterGroup<T> {
final static class FilterGroupResult {
private SettingsEnum setting;
private boolean filtered;
private int matchedIndex;
// In the future it might be useful to include which pattern matched,
// but for now that is not needed.

FilterGroupResult() {
this(null, false, -1);
this(null, -1);
}

FilterGroupResult(SettingsEnum setting, boolean filtered, int matchedIndex) {
setValues(setting, filtered, matchedIndex);
FilterGroupResult(SettingsEnum setting, int matchedIndex) {
setValues(setting, matchedIndex);
}

public void setValues(SettingsEnum setting, boolean filtered, int matchedIndex) {
public void setValues(SettingsEnum setting, int matchedIndex) {
this.setting = setting;
this.filtered = filtered;
this.matchedIndex = matchedIndex;
}

Expand All @@ -43,7 +41,7 @@ public SettingsEnum getSetting() {
}

public boolean isFiltered() {
return filtered;
return matchedIndex >= 0;
}

/**
Expand Down Expand Up @@ -101,11 +99,10 @@ public StringFilterGroup(final SettingsEnum setting, final String... filters) {

@Override
public FilterGroupResult check(final String string) {
final boolean isEnabled = isEnabled();
final int indexOf = isEnabled
final int indexOf = isEnabled()
? ReVancedUtils.indexOfFirstFound(string, filters)
: -1;
return new FilterGroupResult(setting, isEnabled, indexOf);
return new FilterGroupResult(setting, indexOf);
}
}

Expand Down Expand Up @@ -179,7 +176,6 @@ private synchronized void buildFailurePatterns() {

@Override
public FilterGroupResult check(final byte[] bytes) {
var matched = false;
int matchedIndex = -1;
if (isEnabled()) {
if (failurePatterns == null) {
Expand All @@ -188,12 +184,11 @@ public FilterGroupResult check(final byte[] bytes) {
for (int i = 0, length = filters.length; i < length; i++) {
matchedIndex = indexOf(bytes, filters[i], failurePatterns[i]);
if (matchedIndex >= 0) {
matched = true;
break;
}
}
}
return new FilterGroupResult(setting, matched, matchedIndex);
return new FilterGroupResult(setting, matchedIndex);
}
}

Expand Down Expand Up @@ -233,7 +228,7 @@ protected final synchronized void buildSearch() {
search.addPattern(pattern, (textSearched, matchedStartIndex, callbackParameter) -> {
if (group.isEnabled()) {
FilterGroup.FilterGroupResult result = (FilterGroup.FilterGroupResult) callbackParameter;
result.setValues(group.setting, true, matchedStartIndex);
result.setValues(group.setting, matchedStartIndex);
return true;
}
return false;
Expand Down

0 comments on commit 3177625

Please sign in to comment.