Interface StringValidator
- All Superinterfaces:
ObjectComponent<StringValidator,
,String> ValidatorComponent<StringValidator,
String>
public interface StringValidator
extends ValidatorComponent<StringValidator,String>, ObjectComponent<StringValidator,String>
Validates the state of a
String
.-
Method Summary
Modifier and TypeMethodDescriptionEnsures that the value contains some substring.doesNotContain
(String unwanted) Ensures that the value does not contain some substring.Ensures that the value does not contain whitespace characters.doesNotEndWith
(String suffix) Ensures that the value does not end with some suffix.doesNotStartWith
(String prefix) Ensures that the value does not start with some prefix.Ensures that the value ends with some suffix.isBlank()
Ensures that the value is empty or contains onlywhitespace
codepoints.isEmpty()
Ensures that the value is empty.Ensures that the value is not empty or contains non-whitespace
codepoints.Ensures that the value is not empty.Ensures that the value does not contain leading or trailing whitespace, where whitespace is defined byString.strip()
.Ensures that the value does not contain leading or trailing whitespace, where whitespace is defined byString.trim()
.length()
Returns a validator for the length of the String.Ensures that the value matches a regular expression.Ensures that the value matches a regular expression.startsWith
(String prefix) Ensures that the value starts with some prefix.Methods declared in interface com.github.cowwoc.requirements10.java.validator.component.ObjectComponent
getValue, isEqualTo, isEqualTo, isInstanceOf, isInstanceOf, isNotEqualTo, isNotEqualTo, isNotInstanceOf, isNotInstanceOf, isNotNull, isNull, isReferenceEqualTo, isReferenceNotEqualTo
Methods declared in interface com.github.cowwoc.requirements10.java.validator.component.ValidatorComponent
and, elseGetFailures, elseThrow, getContext, getContextAsString, getName, getValueOrDefault, validationFailed, withContext
-
Method Details
-
startsWith
Ensures that the value starts with some prefix.- Parameters:
prefix
- the value that the string must start with- Returns:
- this
- Throws:
NullPointerException
- if the value orprefix
are nullIllegalArgumentException
- if the value does not start withprefix
-
doesNotStartWith
Ensures that the value does not start with some prefix.- Parameters:
prefix
- the value that the string may not start with- Returns:
- this
- Throws:
NullPointerException
- if the value orprefix
are nullIllegalArgumentException
- if the value starts withprefix
-
endsWith
Ensures that the value ends with some suffix.- Parameters:
suffix
- the value that the string must end with- Returns:
- this
- Throws:
NullPointerException
- if the value orsuffix
are nullIllegalArgumentException
- if the value does not end withsuffix
-
doesNotEndWith
Ensures that the value does not end with some suffix.- Parameters:
suffix
- the value that the string may not end with- Returns:
- this
- Throws:
NullPointerException
- if the value orsuffix
are nullIllegalArgumentException
- if the value ends withsuffix
-
contains
Ensures that the value contains some substring.- Parameters:
expected
- the string that the value must contain- Returns:
- this
- Throws:
NullPointerException
- if the value orexpected
are nullIllegalArgumentException
- if the value does not containexpected
-
doesNotContain
Ensures that the value does not contain some substring.- Parameters:
unwanted
- the string that the value may not contain- Returns:
- this
- Throws:
NullPointerException
- if the value orunwanted
are nullIllegalArgumentException
- if the value containsunwanted
-
doesNotContainWhitespace
StringValidator doesNotContainWhitespace()Ensures that the value does not contain whitespace characters.- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the value contains whitespace characters
-
matches
Ensures that the value matches a regular expression.- Parameters:
regex
- the regular expression- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the value does not matchregex
-
matches
Ensures that the value matches a regular expression.- Parameters:
regex
- the regular expression- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the value does not matchregex
-
isEmpty
StringValidator isEmpty()Ensures that the value is empty.- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the value is not empty
-
isNotEmpty
StringValidator isNotEmpty()Ensures that the value is not empty.- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the value is empty
-
isTrimmed
StringValidator isTrimmed()Ensures that the value does not contain leading or trailing whitespace, where whitespace is defined byString.trim()
.- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the value contains leading or trailing whitespace- See Also:
-
isStripped
StringValidator isStripped()Ensures that the value does not contain leading or trailing whitespace, where whitespace is defined byString.strip()
.- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the value contains leading or trailing whitespace- See Also:
-
isBlank
StringValidator isBlank()Ensures that the value is empty or contains onlywhitespace
codepoints.- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the value is not empty or contains non-whitespace codepoints
-
isNotBlank
StringValidator isNotBlank()Ensures that the value is not empty or contains non-whitespace
codepoints.- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the value is empty or contains only whitespace codepoints
-
length
PrimitiveUnsignedIntegerValidator length()Returns a validator for the length of the String.- Returns:
- a validator for the length of the String
- Throws:
NullPointerException
- if the value is null
-