-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement MultiPatternReplaceableResult
fixes #23
- Loading branch information
Showing
3 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/me/dreamerzero/chatregulator/result/MultiPatternReplaceableResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package me.dreamerzero.chatregulator.result; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
import java.util.regex.Matcher; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class MultiPatternReplaceableResult extends Result implements IReplaceable { | ||
private final Matcher[] matchers; | ||
|
||
/** | ||
* Creates a new MultiPatternReplaceableResult | ||
* @param infractionString the infraction string | ||
* @param infricted if it was infricted | ||
* @param matchers the matchers | ||
*/ | ||
public MultiPatternReplaceableResult(String infractionString, boolean infricted, Matcher[] matchers) { | ||
super(infractionString, infricted); | ||
this.matchers = matchers; | ||
} | ||
|
||
@Override | ||
public @Nullable String replaceInfraction() { | ||
throw new UnsupportedOperationException("Not implemented yet"); | ||
} | ||
|
||
/** | ||
* Obtain the corresponding {@link Matcher}s of the detections performed | ||
* | ||
* It can be null if the check has not yet been performed, | ||
* if the check does not return a Matcher | ||
* or because the check gave a negative result | ||
* @return the matcher of this check | ||
*/ | ||
public Matcher[] getMatchers(){ | ||
return this.matchers; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o){ | ||
if(this == o) return true; | ||
if(!(o instanceof PatternResult that)) return false; | ||
return Objects.equals(that.getInfractionString(), this.getInfractionString()) | ||
&& that.isInfraction() == this.isInfraction(); | ||
} | ||
|
||
@Override | ||
public int hashCode(){ | ||
return Objects.hash(this.getInfractionString(), matchers); | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
String string = Arrays.toString(matchers); | ||
if(string.isBlank()){ | ||
return super.toString(); | ||
} | ||
return "PatternResult["+ super.toString() + string + "]"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters