Package student.testingsupport
Class StringNormalizer.RegexNormalizerRule
- java.lang.Object
-
- student.testingsupport.StringNormalizer.NormalizerRule
-
- student.testingsupport.StringNormalizer.RegexNormalizerRule
-
- Direct Known Subclasses:
NormalizerRuleIgnoreLeadingNewlines
,NormalizerRuleTrailingColonPerLine
,NormalizerRuleTrailingSpacePerLine
- Enclosing class:
- StringNormalizer
public static class StringNormalizer.RegexNormalizerRule extends StringNormalizer.NormalizerRule
A highly reusable concrete implementation ofStringNormalizer.NormalizerRule
that applies a series ofregular expression
substitutions.
-
-
Constructor Summary
Constructors Constructor Description RegexNormalizerRule(String displayName, boolean everywhere, String... patterns)
Create a new regular expression rule using a series of pattern/replacement pairs.RegexNormalizerRule(String displayName, String... patterns)
Create a new regular expression rule using a series of pattern/replacement pairs.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
displayName()
Human readable name of the ruleboolean
equals(Object obj)
int
hashCode()
String
normalize(String content)
Normalize a string by applying all of this rule's regular expression pattern/replacement pairs, in order.
-
-
-
Constructor Detail
-
RegexNormalizerRule
public RegexNormalizerRule(String displayName, String... patterns)
Create a new regular expression rule using a series of pattern/replacement pairs. Each pattern/replacement will be applied globally (all matches that can be found). If multiple patterns are given, they will be applied in the order given. Use this form:myRule = new RegexNormalizerRule( "pattern1", "replacement1", "pattern2", "replacement2", ... // As many as you want );
- Parameters:
patterns
- a series of regular expression pattern/replacement pairs (there must be an even number!)
-
RegexNormalizerRule
public RegexNormalizerRule(String displayName, boolean everywhere, String... patterns)
Create a new regular expression rule using a series of pattern/replacement pairs.- Parameters:
everywhere
- True if all pattern/replacements should be applied globally (for every match), or false if the replacements should only be applied to the first match for each pattern.patterns
- a series of regular expression pattern/replacement pairs (there must be an even number!)
-
-
Method Detail
-
hashCode
public int hashCode()
- Specified by:
hashCode
in classStringNormalizer.NormalizerRule
-
equals
public boolean equals(Object obj)
- Specified by:
equals
in classStringNormalizer.NormalizerRule
-
normalize
public String normalize(String content)
Normalize a string by applying all of this rule's regular expression pattern/replacement pairs, in order.- Specified by:
normalize
in classStringNormalizer.NormalizerRule
- Parameters:
content
- The string to transform- Returns:
- The result after all substitutions have been applied
-
displayName
public String displayName()
Description copied from class:StringNormalizer.NormalizerRule
Human readable name of the rule- Specified by:
displayName
in classStringNormalizer.NormalizerRule
- Returns:
- The name
-
-