public abstract class ConstraintFactory extends AnnotationSupport
Constraint
instances.
ConstraintFactory
is thread-safe.
Constraint
DEFAULT_GROUP_SET, DEFAULT_TARGET_SET
Modifier and Type | Method and Description |
---|---|
static <V> Constraint<V> |
and(Class<V> type,
Collection<Constraint<? super V>> constraints)
Returns constraint that is conjunction of the specified constraints.
|
static <V> Constraint<V> |
and(Class<V> type,
Constraint<? super V>... constraints)
Returns constraint that is conjunction of the specified constraints.
|
static <V> Constraint<V> |
and(Collection<Constraint<? super V>> constraints)
Returns constraint that is conjunction of the specified constraints.
|
static <V> Constraint<V> |
and(Constraint<? super V>... constraints)
Returns constraint that is conjunction of the specified constraints.
|
static <V> Constraint<? super V[]> |
arrayElement(Constraint<V> constraint)
Returns constraint that performs validation of array elements.
|
static <V> Constraint<V> |
arrayMaxSize(int max)
Returns constraint that checks whether the length of an array is not
greater than allowed maximum length.
|
static <V> Constraint<V> |
arrayMinSize(int min)
Returns constraint that checks whether the length of an array is not
less than allowed minimum length.
|
static <V> Constraint<V> |
arrayNotEmpty()
Returns constraint that checks whether an array is not empty.
|
static <V> Constraint<V> |
arrayRemoveNullElements()
Returns constraint that removes all
null elements from an
array. |
static <V> Constraint<V> |
arraySize(int min,
int max)
Returns constraint that checks whether the length of an array is within
allowed minimum and maximum bounds.
|
static Constraint<Image> |
awtImageSize(int maxWidth,
int maxHeight,
ImageAdjust adjust)
Returns constraint that checks whether the size of an image is within
maximum bounds.
|
static Constraint<String> |
capitalize()
Returns constraint that converts to upper case first letter of first
word in a string.
|
static Constraint<String> |
capitalizeAll()
Returns constraint that converts to upper case first letters of all
words in a string.
|
static <V> Constraint<V> |
cascade(Class<V> type)
Returns constraint that performs cascade validation on an entity.
|
static <V> Constraint<V> |
cascade(EntityMetaData<V> metadata)
Returns constraint that performs cascade validation on an entity.
|
static Constraint<String> |
coalesce()
Returns constraint that replaces all whitespaces with
' '
character in a string. |
static Constraint<String> |
coalesce(char replacement,
boolean multiline)
Returns constraint that replaces all whitespaces with single character
in a string.
|
static <V> Constraint<? super Collection<V>> |
collectionElement(Constraint<V> constraint)
Returns constraint that performs validation of collection elements.
|
static <V extends Collection<?>> |
collectionMaxSize(int max)
Returns constraint that checks whether the size of a collection is not
greater than allowed maximum size.
|
static <V extends Collection<?>> |
collectionMinSize(int min)
Returns constraint that checks whether the size of a collection is not
less than allowed minimum size.
|
static <V extends Collection<?>> |
collectionNotEmpty()
Returns constraint that checks whether a collection is not empty.
|
static <V extends Collection<?>> |
collectionRemoveNullElements()
Returns constraint that removes all
null elements from a
collection. |
static <V extends Collection<?>> |
collectionSize(int min,
int max)
Returns constraint that checks whether the size of a collection is
within allowed minimum and maximum bounds.
|
static <V> Constraint<? super V> |
createConstraint(Type type,
Annotation[] annotations,
String namespace,
ValidationDefaults defaults)
Creates a new constraint for the specified generic value type using
configuration from the specified annotations.
|
static <V> Constraint<V> |
defaultValue(V defaultValue)
Returns constraint that replaces a
null value with default
value. |
static Constraint<String> |
despace()
Returns constraint that removes all whitespaces from a string.
|
static Constraint<File> |
directoryExists()
Returns constraint that checks existence of a directory.
|
static Constraint<String> |
emailAddress()
Returns constraint that checks whether a string is valid email address.
|
static <V extends Enum<V>> |
enumeration(Class<V> type)
Returns constraint that lists constants of the specified enumeration
type.
|
static <V> Constraint<V> |
enumeration(Class<V> type,
Collection<V> constants)
Returns constraint that checks whether a value is one of the allowed
constants.
|
static <V> Constraint<V> |
enumeration(Class<V> type,
V... constants)
Returns constraint that checks whether a value is one of the allowed
constants.
|
static <V> Constraint<V> |
enumeration(Collection<V> constants)
Returns constraint that checks whether a value is one of the allowed
constants.
|
static <V> Constraint<V> |
enumeration(V... constants)
Returns constraint that checks whether a value is one of the allowed
constants.
|
static <V> Constraint<V> |
eq(Class<V> type,
String property)
Returns constraint that applies
== operator to a value
and the specified property. |
static <V> Constraint<V> |
eq(Class<V> type,
String property,
Comparator<V> comparator)
Returns constraint that applies
== operator to a value
and the specified property. |
static Constraint<File> |
fileExists()
Returns constraint that checks existence of a file.
|
static Constraint<File> |
fileSize(long min,
long max)
Returns constraint that checks whether size of a file is within allowed
minimum and maximum bounds.
|
static <V> Set<V> |
findConstants(Constraint<?> wrapper)
Searches enumeration constants for the specified constraint.
|
static <T extends Constraint<?>> |
findConstraint(Constraint<?> wrapper,
Class<T> requiredType)
Searches constraint by its type in the specified one.
|
static <V> V |
findDefaultValue(Constraint<?> wrapper)
Searches default value for the specified constraint.
|
static Constraint<Date> |
futureDate()
Returns constraint that checks whether a date is date in the future.
|
static Set<String> |
getGroups(Constraint<?> constraint)
Returns set of groups the specified constraint is applied on.
|
static <V extends Comparable<? super V>> |
gt(Class<V> type,
String property)
Returns constraint that applies
> operator to a value
and the specified property. |
static <V> Constraint<V> |
gt(Class<V> type,
String property,
Comparator<V> comparator)
Returns constraint that applies
> operator to a value
and the specified property. |
static <V extends Comparable<? super V>> |
gte(Class<V> type,
String property)
Returns constraint that applies
>= operator to a value
and the specified property. |
static <V> Constraint<V> |
gte(Class<V> type,
String property,
Comparator<V> comparator)
Returns constraint that applies
>= operator to a value
and the specified property. |
static boolean |
hasWrappedMessage(Constraint<?> constraint)
Determines if the specified constraint has wrapped error message.
|
static Constraint<String> |
hostname()
Returns constraint that checks whether a string is valid internet
hostname.
|
static Constraint<String> |
identifier()
Returns constraint that checks whether a string is valid identifier.
|
static <V> Constraint<? super V> |
identity()
Returns constraint that just returns value unchanged.
|
static Constraint<String> |
ignoreCaseEnumeration(Collection<String> constants)
Returns constraint that checks whether a string is one of the allowed
strings ignoring case considerations.
|
static Constraint<String> |
ignoreCaseEnumeration(String... constants)
Returns constraint that checks whether a string is one of the allowed
strings ignoring case considerations.
|
static Constraint<String> |
illegalCharset(String pattern)
Returns constraint that checks whether a string not contains disallowed
characters.
|
static Constraint<String> |
illegalCharset(org.foxlabs.util.UnicodeSet charset)
Returns constraint that checks whether a string not contains disallowed
characters.
|
static Constraint<String> |
inetAddress()
Returns constraint that checks whether a string is valid internet
address (can be either hostname or IP address).
|
static <V> Constraint<? super V> |
instanceOf(Class<?>... types)
Returns constraint that checks whether a value is instance of one of the
specified types.
|
static Constraint<String> |
ip4Address()
Returns constraint that checks whether a string is valid IPv4 address.
|
static Constraint<String> |
ip6Address()
Returns constraint that checks whether a string is valid IPv6 address.
|
static Constraint<String> |
ipAddress()
Returns constraint that checks whether a string is valid IPv4 or IPv6
address.
|
static boolean |
isConstraintAnnotation(Annotation annotation)
Determines if the specified annotation is either constraint annotation
or custom constraint annotation.
|
static Constraint<Boolean> |
isFalse()
Returns constraint that checks whether a boolean value is
false . |
static <V> Constraint<? super V> |
isNull()
Returns constraint that checks whether a value is
null . |
static Constraint<Boolean> |
isTrue()
Returns constraint that checks whether a boolean value is
true . |
static <V> Constraint<V> |
join(Class<V> type,
Collection<Constraint<? super V>> constraints)
Returns constraint that is composition of the specified constraints.
|
static <V> Constraint<V> |
join(Class<V> type,
Constraint<? super V>... constraints)
Returns constraint that is composition of the specified constraints.
|
static <V> Constraint<V> |
join(Collection<Constraint<? super V>> constraints)
Returns constraint that is composition of the specified constraints.
|
static <V> Constraint<V> |
join(Constraint<? super V>... constraints)
Returns constraint that is composition of the specified constraints.
|
static Constraint<String> |
legalCharset(String pattern)
Returns constraint that checks whether a string contains allowed
characters only.
|
static Constraint<String> |
legalCharset(org.foxlabs.util.UnicodeSet charset)
Returns constraint that checks whether a string contains allowed
characters only.
|
static Constraint<Level> |
logLevel()
Returns constraint that checks whether a log level is in list of known
log levels.
|
static Constraint<String> |
lowerCase()
Returns constraint that converts a string to lower case.
|
static <V extends Comparable<? super V>> |
lt(Class<V> type,
String property)
Returns constraint that applies
< operator to a value
and the specified property. |
static <V> Constraint<V> |
lt(Class<V> type,
String property,
Comparator<V> comparator)
Returns constraint that applies
< operator to a value
and the specified property. |
static <V extends Comparable<? super V>> |
lte(Class<V> type,
String property)
Returns constraint that applies
<= operator to a value
and the specified property. |
static <V> Constraint<V> |
lte(Class<V> type,
String property,
Comparator<V> comparator)
Returns constraint that applies
<= operator to a value
and the specified property. |
static <V> Constraint<? super Map<V,Object>> |
mapKey(Constraint<V> constraint)
Returns constraint that performs validation of map keys.
|
static <V extends Map<?,?>> |
mapMaxSize(int max)
Returns constraint that checks whether the size of a map is not greater
than allowed maximum size.
|
static <V extends Map<?,?>> |
mapMinSize(int min)
Returns constraint that checks whether the size of a map is not less
than allowed minimum size.
|
static <V extends Map<?,?>> |
mapNotEmpty()
Returns constraint that checks whether a map is not empty.
|
static <V extends Map<?,?>> |
mapSize(int min,
int max)
Returns constraint that checks whether the size of a map is within
allowed minimum and maximum bounds.
|
static <V> Constraint<? super Map<Object,V>> |
mapValue(Constraint<V> constraint)
Returns constraint that performs validation of map values.
|
static <V extends Comparable<? super V>> |
max(V max)
Returns constraint that checks whether a value is not greater than
allowed maximum value.
|
static <V> Constraint<V> |
max(V max,
Comparator<V> comparator)
Returns constraint that checks whether a value is not greater than
allowed maximum value.
|
static Constraint<String> |
maxLength(int limit)
Returns constraint that allows to cut length of a string.
|
static Constraint<String> |
mimetype()
Returns constraint that checks whether a string is valid mime type
representation.
|
static <V extends Comparable<? super V>> |
min(V min)
Returns constraint that checks whether a value is not less than
allowed minimum value.
|
static <V> Constraint<V> |
min(V min,
Comparator<V> comparator)
Returns constraint that checks whether a value is not less than
allowed minimum value.
|
static <V> Constraint<V> |
ne(Class<V> type,
String property)
Returns constraint that applies
!= operator to a value
and the specified property. |
static <V> Constraint<V> |
ne(Class<V> type,
String property,
Comparator<V> comparator)
Returns constraint that applies
!= operator to a value
and the specified property. |
static <V> Constraint<V> |
not(Class<V> type,
Collection<Constraint<? super V>> constraints)
Returns constraint that is negation of the specified constraints.
|
static <V> Constraint<V> |
not(Class<V> type,
Constraint<? super V>... constraints)
Returns constraint that is negation of the specified constraints.
|
static <V> Constraint<V> |
not(Collection<Constraint<? super V>> constraints)
Returns constraint that is negation of the specified constraints.
|
static <V> Constraint<V> |
not(Constraint<? super V>... constraints)
Returns constraint that is negation of the specified constraints.
|
static Constraint<String> |
notBlank()
Returns constraint that checks whether a string is not
null
or empty. |
static <V> Constraint<? super V> |
notNull()
Returns constraint that checks whether a value is not
null . |
static Constraint<String> |
nullify()
Returns constraint that replaces an empty string with
null . |
static <V> Constraint<V> |
or(Class<V> type,
Collection<Constraint<? super V>> constraints)
Returns constraint that is disjunction of the specified constraints.
|
static <V> Constraint<V> |
or(Class<V> type,
Constraint<? super V>... constraints)
Returns constraint that is disjunction of the specified constraints.
|
static <V> Constraint<V> |
or(Collection<Constraint<? super V>> constraints)
Returns constraint that is disjunction of the specified constraints.
|
static <V> Constraint<V> |
or(Constraint<? super V>... constraints)
Returns constraint that is disjunction of the specified constraints.
|
static Constraint<Date> |
pastDate()
Returns constraint that checks whether a date is date in the past.
|
static <V extends Comparable<? super V>> |
range(V min,
V max)
Returns constraint that checks whether a value is within allowed
minimum and maximum range.
|
static <V> Constraint<V> |
range(V min,
V max,
Comparator<V> comparator)
Returns constraint that checks whether a value is within allowed
minimum and maximum range.
|
static Constraint<byte[]> |
rawImageSize(int maxWidth,
int maxHeight,
ImageAdjust adjust)
Returns constraint that checks whether the size of a raw image is within
maximum bounds.
|
static Constraint<String> |
regex(String pattern)
Returns constraint that checks whether a string matches the regular
expression.
|
static Constraint<String> |
regex(String pattern,
int flags)
Returns constraint that checks whether a string matches the regular
expression.
|
static Constraint<String> |
replace(String regex,
String replacement)
Returns constraint that replaces each substring of a string that matches
the given regular expression with the given replacement.
|
static Constraint<String> |
replace(String regex,
String replacement,
int flags)
Returns constraint that replaces each substring of a string that matches
the given regular expression with the given replacement.
|
static <V> Constraint<V> |
setNull()
Returns constraint that replaces a value with
null . |
static Constraint<String> |
stringMaxSize(int max)
Returns constraint that checks whether the length of a string is not
greater than allowed maximum length.
|
static Constraint<String> |
stringMinSize(int min)
Returns constraint that checks whether the length of a string is not
less than allowed minimum length.
|
static Constraint<String> |
stringNotEmpty()
Returns constraint that checks whether a string is not empty.
|
static Constraint<String> |
stringSize(int min,
int max)
Returns constraint that checks whether the length of a string is within
allowed minimum and maximum bounds.
|
static Constraint<String> |
supportedEncoding()
Returns constraint that checks whether a string is in list of available
charset names supported by JRE.
|
static Constraint<String> |
supportedImageMime()
Returns constraint that checks whether a string is in list of available
image MIME types supported by
javax.imageio.ImageIO . |
static Constraint<Locale> |
supportedLocale()
Returns constraint that checks whether a locale is in list of available
locales supported by JRE.
|
static Constraint<TimeZone> |
supportedTimeZone()
Returns constraint that checks whether a time zone is in list of
available time zones supported by JRE.
|
static Constraint<Date> |
sysdate()
Returns constraint that replaces a
null date with current
system date. |
static Constraint<String> |
trim()
Returns constraint that removes leading and trailing whitespaces from a
string.
|
static <V> Constraint<V> |
unwrapConstraint(Constraint<V> wrapper)
Returns unwrapped constraint for the specified one.
|
static Constraint<String> |
upperCase()
Returns constraint that converts a string to upper case.
|
static Constraint<String> |
uriAddress()
Returns constraint that checks whether a string is valid URI reference.
|
static Constraint<String> |
uriAddress(String... schemes)
Returns constraint that checks whether a string is valid URI reference
with allowed scheme.
|
static Constraint<String> |
urlAddress()
Returns constraint that checks whether a string is valid URL reference.
|
static Constraint<String> |
urlAddress(String prefix,
String... protocols)
Returns constraint that checks whether a string is valid URL reference
with allowed prefix and protocol.
|
static <V> Constraint<V> |
wrapGroups(Constraint<V> constraint)
Wraps groups of the specified constraint by default.
|
static <V> Constraint<V> |
wrapGroups(Constraint<V> constraint,
String... groups)
Wraps groups of the specified constraint.
|
static <V> Constraint<V> |
wrapMessage(Constraint<V> constraint,
String message)
Wraps error message of the specified constraint.
|
addToCache, addToCache, createValidation, getAnnotationGroups, getAnnotationList, getAnnotationMessage, getAnnotationProperty, getAnnotationTargets, getFromCache, isAnnotationPresent
public static <V> Constraint<? super V> isNull()
null
.V
- The value type.null
.IsNullConstraint
public static Constraint<Boolean> isTrue()
true
.true
.IsTrueConstraint
public static Constraint<Boolean> isFalse()
false
.false
.IsFalseConstraint
public static <V> Constraint<? super V> notNull()
null
.V
- The value type.null
.NotNullConstraint
public static Constraint<String> notBlank()
null
or empty.null
or empty.NotBlankConstraint
public static Constraint<String> stringNotEmpty()
NotEmptyConstraint.StringType
public static <V> Constraint<V> arrayNotEmpty()
V
- The array type.NotEmptyConstraint.ArrayType
public static <V extends Collection<?>> Constraint<V> collectionNotEmpty()
V
- The collection type.NotEmptyConstraint.CollectionType
public static <V extends Map<?,?>> Constraint<V> mapNotEmpty()
V
- The map type.NotEmptyConstraint.MapType
public static Constraint<String> stringMinSize(int min)
min
- Minimum length of a string.stringSize(int, int)
,
SizeConstraint.StringType
public static Constraint<String> stringMaxSize(int max)
max
- Maximum length of a string.stringSize(int, int)
,
SizeConstraint.StringType
public static Constraint<String> stringSize(int min, int max)
min
- Minimum length of a string.max
- Maximum length of a string.SizeConstraint.StringType
public static <V> Constraint<V> arrayMinSize(int min)
V
- The array type.min
- Minimum length of an array.arraySize(int, int)
,
SizeConstraint.ArrayType
public static <V> Constraint<V> arrayMaxSize(int max)
V
- The array type.max
- Maximum length of an array.arraySize(int, int)
,
SizeConstraint.ArrayType
public static <V> Constraint<V> arraySize(int min, int max)
V
- The array type.min
- Minimum length of an array.max
- Maximum length of an array.SizeConstraint.ArrayType
public static <V extends Collection<?>> Constraint<V> collectionMinSize(int min)
V
- The collection type.min
- Minimum size of a collection.collectionSize(int, int)
,
SizeConstraint.CollectionType
public static <V extends Collection<?>> Constraint<V> collectionMaxSize(int max)
V
- The collection type.max
- Maximum size of a collection.collectionSize(int, int)
,
SizeConstraint.CollectionType
public static <V extends Collection<?>> Constraint<V> collectionSize(int min, int max)
V
- The collection type.min
- Minimum size of a collection.max
- Maximum size of a collection.SizeConstraint.CollectionType
public static <V extends Map<?,?>> Constraint<V> mapMinSize(int min)
V
- The map type.min
- Minimum size of a map.mapSize(int, int)
,
SizeConstraint.MapType
public static <V extends Map<?,?>> Constraint<V> mapMaxSize(int max)
V
- The map type.max
- Maximum size of a map.mapSize(int, int)
,
SizeConstraint.MapType
public static <V extends Map<?,?>> Constraint<V> mapSize(int min, int max)
V
- The map type.min
- Minimum size of a map.max
- Maximum size of a map.SizeConstraint.MapType
public static <V extends Comparable<? super V>> Constraint<V> min(V min)
V
- The value type.min
- Minimum value.range(Object, Object, Comparator)
,
RangeConstraint
public static <V> Constraint<V> min(V min, Comparator<V> comparator)
V
- The value type.min
- Minimum value.comparator
- Comparator to be used for range checking.range(Object, Object, Comparator)
,
RangeConstraint
public static <V extends Comparable<? super V>> Constraint<V> max(V max)
V
- The value type.max
- Maximum value.range(Object, Object, Comparator)
,
RangeConstraint
public static <V> Constraint<V> max(V max, Comparator<V> comparator)
V
- The value type.max
- Maximum value.comparator
- Comparator to be used for range checking.range(Object, Object, Comparator)
,
RangeConstraint
public static <V extends Comparable<? super V>> Constraint<V> range(V min, V max)
V
- The value type.min
- Minimum value.max
- Maximum value.range(Object, Object, Comparator)
,
RangeConstraint
public static <V> Constraint<V> range(V min, V max, Comparator<V> comparator)
V
- The value type.min
- Minimum value.max
- Maximum value.comparator
- Comparator to be used for range checking.RangeConstraint
public static <V extends Enum<V>> Constraint<V> enumeration(Class<V> type)
V
- The enumeration type.type
- Enumeration type.enumeration(Object...)
,
EnumerationConstraint.Default
public static <V> Constraint<V> enumeration(V... constants)
V
- The constants type.constants
- Array of allowed constants.EnumerationConstraint.Default
public static <V> Constraint<V> enumeration(Class<V> type, V... constants)
V
- The constants type.type
- Type of enumeration constants.constants
- Array of allowed constants.EnumerationConstraint.Default
public static <V> Constraint<V> enumeration(Collection<V> constants)
V
- The constants type.constants
- Collection of allowed constants.EnumerationConstraint.Default
public static <V> Constraint<V> enumeration(Class<V> type, Collection<V> constants)
V
- The constants type.type
- Type of enumeration constants.constants
- Collection of allowed constants.EnumerationConstraint.Default
public static Constraint<String> ignoreCaseEnumeration(String... constants)
constants
- Array of allowed strings.IgnoreCaseEnumerationConstraint
public static Constraint<String> ignoreCaseEnumeration(Collection<String> constants)
constants
- Collection of allowed strings.IgnoreCaseEnumerationConstraint
public static Constraint<Locale> supportedLocale()
SupportedLocaleConstraint
public static Constraint<TimeZone> supportedTimeZone()
SupportedTimeZoneConstraint
public static Constraint<String> supportedEncoding()
SupportedEncodingConstraint
public static Constraint<String> supportedImageMime()
javax.imageio.ImageIO
.javax.imageio.ImageIO
.SupportedImageMimeConstraint
public static Constraint<Level> logLevel()
LogLevelConstraint
public static Constraint<String> regex(String pattern)
pattern
- Regular expression pattern.regex(String, int)
,
RegexConstraint
public static Constraint<String> regex(String pattern, int flags)
pattern
- Regular expression pattern.flags
- Match flags.RegexConstraint
public static Constraint<String> mimetype()
MimeTypeConstraint
public static <V> Constraint<? super V> identity()
V
- The value type.IdentityConstraint
public static <V> Constraint<? super V> instanceOf(Class<?>... types)
V
- The value type.types
- The types to check.InstanceOfConstraint
public static Constraint<Date> pastDate()
PastDateConstraint
public static Constraint<Date> futureDate()
FutureDateConstraint
public static Constraint<String> legalCharset(String pattern)
pattern
- Allowed characters pattern.legalCharset(UnicodeSet)
,
LegalCharsetConstraint
,
UnicodeSet.fromPattern(String)
public static Constraint<String> legalCharset(org.foxlabs.util.UnicodeSet charset)
charset
- Allowed character set.LegalCharsetConstraint
public static Constraint<String> illegalCharset(String pattern)
pattern
- Disallowed characters pattern.illegalCharset(UnicodeSet)
,
IllegalCharsetConstraint
,
UnicodeSet.fromPattern(String)
public static Constraint<String> illegalCharset(org.foxlabs.util.UnicodeSet charset)
charset
- Disallowed character set.IllegalCharsetConstraint
public static Constraint<String> identifier()
IdentifierConstraint
public static Constraint<String> hostname()
HostnameConstraint
public static Constraint<String> ip4Address()
Ip4AddressConstraint
public static Constraint<String> ip6Address()
Ip6AddressConstraint
public static Constraint<String> ipAddress()
IpAddressConstraint
public static Constraint<String> inetAddress()
InetAddressConstraint
public static Constraint<String> emailAddress()
EmailAddressConstraint
public static Constraint<String> urlAddress()
UrlAddressConstraint
public static Constraint<String> urlAddress(String prefix, String... protocols)
prefix
- URL prefix pattern if any.protocols
- Array of allowed protocols.UrlAddressConstraint
public static Constraint<String> uriAddress()
UriAddressConstraint
public static Constraint<String> uriAddress(String... schemes)
schemes
- Array of allowed schemes.UriAddressConstraint
public static Constraint<File> fileExists()
FileExistsConstraint
public static Constraint<File> directoryExists()
FileExistsConstraint
public static Constraint<File> fileSize(long min, long max)
min
- Minimum allowed file size.max
- Maximum allowed file size.FileSizeConstraint
public static Constraint<Image> awtImageSize(int maxWidth, int maxHeight, ImageAdjust adjust)
maxWidth
- Maximum image width.maxHeight
- Maximum image height.adjust
- Image size adjust mode.ImageSizeConstraint.AwtCodec
public static Constraint<byte[]> rawImageSize(int maxWidth, int maxHeight, ImageAdjust adjust)
maxWidth
- Maximum image width.maxHeight
- Maximum image height.adjust
- Image size adjust mode.ImageSizeConstraint.RawCodec
public static <V> Constraint<V> setNull()
null
.V
- The value type.null
.SetNullConstraint
public static Constraint<String> nullify()
null
.null
.NullifyConstraint
public static Constraint<String> trim()
TrimConstraint
public static Constraint<String> despace()
DespaceConstraint
public static Constraint<String> coalesce()
' '
character in a string.' '
character in a string.CoalesceConstraint
public static Constraint<String> coalesce(char replacement, boolean multiline)
replacement
- Whitespaces replacement character.multiline
- Determines if new line characters should be preserved.CoalesceConstraint
public static Constraint<String> upperCase()
UpperCaseConstraint
public static Constraint<String> lowerCase()
LowerCaseConstraint
public static Constraint<String> capitalize()
CapitalizeConstraint
public static Constraint<String> capitalizeAll()
CapitalizeAllConstraint
public static Constraint<String> replace(String regex, String replacement)
regex
- Regular expression pattern.replacement
- String to be substituted for each match.replace(String, String, int)
,
ReplaceConstraint
public static Constraint<String> replace(String regex, String replacement, int flags)
regex
- Regular expression pattern.replacement
- String to be substituted for each match.flags
- Match flags.ReplaceConstraint
public static Constraint<String> maxLength(int limit)
limit
- Maximum string length.MaxLengthConstraint
public static Constraint<Date> sysdate()
null
date with current
system date.null
date with current
system date.SysdateConstraint
public static <V> Constraint<V> defaultValue(V defaultValue)
null
value with default
value.V
- The value type.defaultValue
- Default value.null
value with default
value.DefaultValueConstraint
public static <V> Constraint<V> arrayRemoveNullElements()
null
elements from an
array.V
- The array type.null
elements from an
array.public static <V extends Collection<?>> Constraint<V> collectionRemoveNullElements()
null
elements from a
collection.V
- The collection type.null
elements from a
collection.public static <V> Constraint<V> eq(Class<V> type, String property)
==
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.==
operator to a value
and the specified property.eq(Class, String, Comparator)
,
PropertyComparisonConstraint.EqualToOp
public static <V> Constraint<V> eq(Class<V> type, String property, Comparator<V> comparator)
==
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.comparator
- Comparator to be used for operands comparison.==
operator to a value
and the specified property.PropertyComparisonConstraint.EqualToOp
public static <V> Constraint<V> ne(Class<V> type, String property)
!=
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.!=
operator to a value
and the specified property.ne(Class, String, Comparator)
,
PropertyComparisonConstraint.NotEqualToOp
public static <V> Constraint<V> ne(Class<V> type, String property, Comparator<V> comparator)
!=
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.comparator
- Comparator to be used for operands comparison.!=
operator to a value
and the specified property.PropertyComparisonConstraint.NotEqualToOp
public static <V extends Comparable<? super V>> Constraint<V> lt(Class<V> type, String property)
<
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.<
operator to a value
and the specified property.lt(Class, String, Comparator)
,
PropertyComparisonConstraint.LessThanOp
public static <V> Constraint<V> lt(Class<V> type, String property, Comparator<V> comparator)
<
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.comparator
- Comparator to be used for operands comparison.<
operator to a value
and the specified property.PropertyComparisonConstraint.LessThanOp
public static <V extends Comparable<? super V>> Constraint<V> lte(Class<V> type, String property)
<=
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.<=
operator to a value
and the specified property.lte(Class, String, Comparator)
,
PropertyComparisonConstraint.LessThanEqualOp
public static <V> Constraint<V> lte(Class<V> type, String property, Comparator<V> comparator)
<=
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.comparator
- Comparator to be used for operands comparison.<=
operator to a value
and the specified property.PropertyComparisonConstraint.LessThanEqualOp
public static <V extends Comparable<? super V>> Constraint<V> gt(Class<V> type, String property)
>
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.>
operator to a value
and the specified property.gt(Class, String, Comparator)
,
PropertyComparisonConstraint.GreaterThanOp
public static <V> Constraint<V> gt(Class<V> type, String property, Comparator<V> comparator)
>
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.comparator
- Comparator to be used for operands comparison.>
operator to a value
and the specified property.PropertyComparisonConstraint.GreaterThanOp
public static <V extends Comparable<? super V>> Constraint<V> gte(Class<V> type, String property)
>=
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.>=
operator to a value
and the specified property.gte(Class, String, Comparator)
,
PropertyComparisonConstraint.GreaterThanEqualOp
public static <V> Constraint<V> gte(Class<V> type, String property, Comparator<V> comparator)
>=
operator to a value
and the specified property.V
- The property value type.type
- Type of the operands.property
- Property name of the second operand.comparator
- Comparator to be used for operands comparison.>=
operator to a value
and the specified property.PropertyComparisonConstraint.GreaterThanEqualOp
public static <V> Constraint<V> join(Collection<Constraint<? super V>> constraints)
V
- The value type.constraints
- Collection of constraints to be used for validation
of a value.join(Class, Constraint...)
,
ConstraintComposition
public static <V> Constraint<V> join(Class<V> type, Collection<Constraint<? super V>> constraints)
V
- The value type.type
- The type of value to be validated.constraints
- Collection of constraints to be used for validation
of a value.join(Class, Constraint...)
,
ConstraintComposition
public static <V> Constraint<V> join(Constraint<? super V>... constraints)
V
- The value type.constraints
- Array of constraints to be used for validation of a
value.join(Class, Constraint...)
,
ConstraintComposition
public static <V> Constraint<V> join(Class<V> type, Constraint<? super V>... constraints)
V
- The value type.type
- The type of value to be validated.constraints
- Array of constraints to be used for validation of a
value.ConstraintComposition
public static <V> Constraint<V> not(Collection<Constraint<? super V>> constraints)
V
- The value type.constraints
- Collection of constraints to be used for validation
of a value.not(Class, Constraint...)
,
ConstraintNegation
public static <V> Constraint<V> not(Class<V> type, Collection<Constraint<? super V>> constraints)
V
- The value type.type
- The type of value to be validated.constraints
- Collection of constraints to be used for validation
of a value.not(Class, Constraint...)
,
ConstraintNegation
public static <V> Constraint<V> not(Constraint<? super V>... constraints)
V
- The value type.constraints
- Array of constraints to be used for validation of a
value.not(Class, Constraint...)
,
ConstraintNegation
public static <V> Constraint<V> not(Class<V> type, Constraint<? super V>... constraints)
V
- The value type.type
- The type of value to be validated.constraints
- Array of constraints to be used for validation of a
value.ConstraintNegation
public static <V> Constraint<V> and(Collection<Constraint<? super V>> constraints)
V
- The value type.constraints
- Collection of constraints to be used for validation
of a value.and(Class, Constraint...)
,
ConstraintConjunction
public static <V> Constraint<V> and(Class<V> type, Collection<Constraint<? super V>> constraints)
V
- The value type.type
- The type of value to be validated.constraints
- Collection of constraints to be used for validation
of a value.and(Class, Constraint...)
,
ConstraintConjunction
public static <V> Constraint<V> and(Constraint<? super V>... constraints)
V
- The value type.constraints
- Array of constraints to be used for validation of a
value.and(Class, Constraint...)
,
ConstraintConjunction
public static <V> Constraint<V> and(Class<V> type, Constraint<? super V>... constraints)
V
- The value type.type
- The type of value to be validated.constraints
- Array of constraints to be used for validation of a
value.ConstraintConjunction
public static <V> Constraint<V> or(Collection<Constraint<? super V>> constraints)
V
- The value type.constraints
- Collection of constraints to be used for validation
of a value.or(Class, Constraint...)
,
ConstraintDisjunction
public static <V> Constraint<V> or(Class<V> type, Collection<Constraint<? super V>> constraints)
V
- The value type.type
- The type of value to be validated.constraints
- Collection of constraints to be used for validation
of a value.or(Class, Constraint...)
,
ConstraintDisjunction
public static <V> Constraint<V> or(Constraint<? super V>... constraints)
V
- The value type.constraints
- Array of constraints to be used for validation of a
value.or(Class, Constraint...)
,
ConstraintDisjunction
public static <V> Constraint<V> or(Class<V> type, Constraint<? super V>... constraints)
V
- The value type.type
- The type of value to be validated.constraints
- Array of constraints to be used for validation of a
value.ConstraintDisjunction
public static <V> Constraint<? super V[]> arrayElement(Constraint<V> constraint)
V
- The array elements type.constraint
- Constraint to be used for validation of array elements.ArrayElementConstraint
public static <V> Constraint<? super Collection<V>> collectionElement(Constraint<V> constraint)
V
- The collection elements type.constraint
- Constraint to be used for validation of collection
elements.CollectionElementConstraint
public static <V> Constraint<? super Map<V,Object>> mapKey(Constraint<V> constraint)
V
- The map keys type.constraint
- Constraint to be used for validation of map keys.MapKeyConstraint
public static <V> Constraint<? super Map<Object,V>> mapValue(Constraint<V> constraint)
V
- The map values type.constraint
- Constraint to be used for validation of map values.MapValueConstraint
public static <V> Constraint<V> cascade(Class<V> type)
V
- The entity type.type
- The type of entity to be validated.CascadeConstraint
public static <V> Constraint<V> cascade(EntityMetaData<V> metadata)
V
- The entity type.metadata
- Entity metadata.CascadeConstraint
public static <V> Constraint<V> wrapMessage(Constraint<V> constraint, String message)
Note that this method has no effect if the specified constraint is
instance of the CorrectConstraint
.
V
- The value type.constraint
- Constraint to be wrapped.message
- Error message template key.ConstraintMessageWrapper
public static boolean hasWrappedMessage(Constraint<?> constraint)
constraint
- Constraint to be tested.true
if the specified constraint has wrapped
error message; false
otherwise.ConstraintMessageWrapper
public static Set<String> getGroups(Constraint<?> constraint)
constraint
- Constraint whose groups to be returned.public static <V> Constraint<V> wrapGroups(Constraint<V> constraint, String... groups)
V
- The value type.constraint
- Constraint to be wrapped.groups
- Array of constraint groups.ConstraintGroupWrapper
public static <V> Constraint<V> wrapGroups(Constraint<V> constraint)
V
- The value type.constraint
- Constraint to be wrapped.ConstraintGroupWrapper
public static <V> Constraint<V> unwrapConstraint(Constraint<V> wrapper)
V
- The value type.wrapper
- Wrapper constraint.ConstraintWrapper
public static <T extends Constraint<?>> T findConstraint(Constraint<?> wrapper, Class<T> requiredType)
T
- The constraint type.wrapper
- Wrapper or aggregation constraint.requiredType
- Type of the required constraint.null
if there is no required constraint found.public static <V> Set<V> findConstants(Constraint<?> wrapper)
V
- The constants type.wrapper
- Wrapper or aggregation constraint.public static <V> V findDefaultValue(Constraint<?> wrapper)
V
- The value type.wrapper
- Wrapper or aggregation constraint.null
if there is no default value
constraint found.public static boolean isConstraintAnnotation(Annotation annotation)
annotation
- Annotation to be tested.true
if the specified annotation is either
constraint annotation or custom constraint annotation;
false
otherwise.public static <V> Constraint<? super V> createConstraint(Type type, Annotation[] annotations, String namespace, ValidationDefaults defaults)
This method may return null
if there are no constraint
annotations specified. Annotations that are not constraint annotations
would be skipped.
V
- The value type.type
- The type of value to be validated.annotations
- Array of annotations.namespace
- Namespace (for example, qualified property name).defaults
- Validation defaults.null
if there are no constraint
annotations specified.ValidationTargetException
- if there is an error in constraint
declaration.createConstraint(Class, Annotation, String, ValidationDefaults)
Copyright © 2011–2020 FoxLabs. All rights reserved.