public class ReplaceConstraint extends CorrectConstraint<String>
CorrectConstraint
implementation that
Replaces each substring of a string that matches the given regular
expression with the given replacement.Replace
,
ConstraintFactory.replace(String, String)
,
ConstraintFactory.replace(String, String, int)
Modifier and Type | Field and Description |
---|---|
protected Pattern |
pattern
Compiled representation of a regular expression.
|
protected String |
replacement
String to be substituted for each match.
|
Modifier | Constructor and Description |
---|---|
protected |
ReplaceConstraint(String regex,
String replacement,
int flags)
Constructs a new
ReplaceConstraint with the specified
regular expression, substitution string and match flags. |
Modifier and Type | Method and Description |
---|---|
Pattern |
getPattern()
Returns compiled representation of a regular expression.
|
String |
getReplacement()
Returns string to be substituted for each match.
|
Class<?> |
getType()
Returns
java.lang.String type. |
<T> String |
validate(String value,
ValidationContext<T> context)
Replaces each substring of the specified string that matches the given
regular expression with the given replacement.
|
getMessageTemplate
appendMessageArguments
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
appendMessageArguments
protected final Pattern pattern
protected final String replacement
protected ReplaceConstraint(String regex, String replacement, int flags)
ReplaceConstraint
with the specified
regular expression, substitution string and match flags.regex
- Regular expression pattern.replacement
- String to be substituted for each match.flags
- Match flags.IllegalArgumentException
- if the specified regular expression is
null
or invalid or the specified replacement string
is null
.public final Class<?> getType()
java.lang.String
type.java.lang.String
type.public final Pattern getPattern()
public final String getReplacement()
public <T> String validate(String value, ValidationContext<T> context)
T
- The type of validated entity.value
- Source string.context
- Validation context.Copyright © 2011–2020 FoxLabs. All rights reserved.