V
- The type of value to be validatedpublic abstract class SizeConstraint<V> extends CheckConstraint<V>
CheckConstraint
that checks whether the size of a value is within allowed minimum and
maximum bounds.Modifier and Type | Class and Description |
---|---|
static class |
SizeConstraint.ArrayType
This class provides
SizeConstraint implementation for all
array types. |
static class |
SizeConstraint.CollectionType
This class provides
SizeConstraint implementation for all
JDK java.util.Collection types. |
static class |
SizeConstraint.MapType
This class provides
SizeConstraint implementation for all
JDK java.util.Map types. |
static class |
SizeConstraint.StringType
This class provides
SizeConstraint implementation for
java.lang.String type. |
Modifier | Constructor and Description |
---|---|
protected |
SizeConstraint(int minSize,
int maxSize)
Constructs a new
SizeConstraint with the specified minimum
and maximum sizes. |
Modifier and Type | Method and Description |
---|---|
boolean |
appendMessageArguments(ValidationContext<?> context,
Map<String,Object> arguments)
Appends
minSize and maxSize arguments that
contain minimum and maximum allowed size respectively. |
protected <T> boolean |
check(V value,
ValidationContext<T> context)
Checks whether the size of the specified value is within allowed
minimum and maximum bounds.
|
int |
getMaxSize()
Returns allowed maximum size.
|
String |
getMessageTemplate(ValidationContext<?> context)
Returns localized error message template.
|
int |
getMinSize()
Returns allowed minimum size.
|
protected abstract <T> int |
getSize(V value,
ValidationContext<T> context)
Returns size of the specified value.
|
validate
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getType
protected SizeConstraint(int minSize, int maxSize)
SizeConstraint
with the specified minimum
and maximum sizes.minSize
- Minimum allowed size.maxSize
- Maximum allowed size.IllegalArgumentException
- if the specified minimum or maximum size
is negative.public final int getMinSize()
public final int getMaxSize()
public String getMessageTemplate(ValidationContext<?> context)
getMessageTemplate
in interface Constraint<V>
getMessageTemplate
in interface Validation<V>
getMessageTemplate
in class AbstractValidation<V>
context
- Validation context.public boolean appendMessageArguments(ValidationContext<?> context, Map<String,Object> arguments)
minSize
and maxSize
arguments that
contain minimum and maximum allowed size respectively.appendMessageArguments
in interface Constraint<V>
appendMessageArguments
in interface Validation<V>
appendMessageArguments
in class AbstractValidation<V>
context
- Validation context.arguments
- Arguments to be substituted into the error message
template.true
.protected final <T> boolean check(V value, ValidationContext<T> context)
check
in class CheckConstraint<V>
T
- The type of validated entity.value
- Value which size to be checked.context
- Validation context.true
if the size of the specified value is within
allowed bounds; false
otherwise.protected abstract <T> int getSize(V value, ValidationContext<T> context)
T
- The type of validated entity.value
- Value which size to be returned.context
- Validation context.Copyright © 2011–2020 FoxLabs. All rights reserved.