public interface ValidationSet extends ToJsonObjectConvertible
You create a validation set then you add some validation Messages to
it, manually using the addMessage
similar methods, or by using some provided validators, such as
validationNotBlank().
Multiple validation sets can be grouped together using the
mergeValidationSet(ValidationSet) related methods. This
means you can validate some elements independently, then group
the results together to form a final validation set.
| Modifier and Type | Method and Description |
|---|---|
ValidationSet |
addError(String validationKey,
String code,
String text)
Creates and adds a new Error validation Message.
|
ValidationSet |
addMessage(String validationKey,
ValidationLevel messageLevel,
String code,
String text)
Creates and adds a new validation Message.
|
ValidationSet |
addMessage(String validationKey,
ValidationMessage validationMessage)
Adds a new validation Message to this set, using the
specified validation key.
|
ValidationSet |
addSuccess(String validationKey,
String code,
String text)
Creates and adds a new Success validation Message.
|
ValidationSet |
addWarning(String validationKey,
String code,
String text)
Creates and adds a new Warning validation Message.
|
JsonObject |
convertToJsonObject()
Converts the set to a
JsonObject object. |
ValidationSet |
createValidationSet()
Creates a new, empty, validation set.
|
Map<String,List<ValidationMessage>> |
getMessages()
Gets the validation keys and their
associated messages.
|
List<ValidationMessage> |
getMessages(String validationKey)
Gets the validation messages for the specified key.
|
String |
getMessagesFormatted(String validationKey,
ValidationMessageFormatType formatType)
Quick way to get a formatted version of the validation
messages for the specified key.
|
String |
getMessagesFormatted(ValidationMessageFormatType formatType)
Quick way to get a formatted version of all validation
messages.
|
boolean |
hasMessages()
Does this validation set contain any validation
Messages?
|
boolean |
hasMessages(String validationKey)
Does the the element at the specified key
contains validation Messages?
|
boolean |
isError()
Returns
true if the validation set
contains at least one ERROR message. |
boolean |
isError(String validationKey)
Returns
true if the validation set
for the element at the specified key contains
at least one ERROR message. |
boolean |
isSuccess()
Returns
true if the validation set
only contains SUCCESS messages
(or contains no messages at all). |
boolean |
isSuccess(String validationKey)
Returns
true if the validation set
for the element at the specified key only contains
SUCCESS messages
(or contains no messages at all). |
boolean |
isValid()
Returns
true if the validation set
does not contain ERROR messages. |
boolean |
isValid(String validationKey)
Returns
true if the validation set
for the element at the specified key
does not contain ERROR messages. |
boolean |
isWarning()
Returns
true if the validation set
contains at least one WARNING message, but no
ERROR messages. |
boolean |
isWarning(String validationKey)
Returns
true if the validation set
for the element at the specified key contains at
least one WARNING message, but no
ERROR messages. |
ValidationSet |
mergeValidationSet(String validationKeyPrefix,
ValidationSet result)
Adds an existing validation set and prefix all the
validation keys of this Set using the
validationKeyPrefix. |
ValidationSet |
mergeValidationSet(ValidationSet set)
Merges an existing validation set.
|
ValidationSet |
prefixValidationKeys(String prefix)
Prefix all the currently existing validation keys in this Set
with the specified prefix.
|
ValidationBuilderKey |
validation(SimpleValidator validator)
Starts a validation using a
custom
SimpleValidator. |
ValidationBuilderKey |
validationBlank()
Starts the creation of a "must be blank" validation.
|
ValidationBuilderKey |
validationEmail()
Starts the creation of a "email" validation.
|
ValidationBuilderKey |
validationEquivalent(Object reference)
Starts the creation of a "equivalent" validation.
|
ValidationBuilderKey |
validationEquivalentOrGreater(Object reference)
Starts the creation of a "equivalent or greater" validation.
|
ValidationBuilderKey |
validationEquivalentOrLess(Object reference)
Starts the creation of a "equivalent or less" validation.
|
ValidationBuilderKey |
validationGreater(Object reference)
Starts the creation of a "greater than" validation.
|
ValidationBuilderKey |
validationLength(int length)
Starts the creation of a "length" validation.
|
ValidationBuilderKey |
validationLess(Object reference)
Starts the creation of a "less than" validation.
|
ValidationBuilderKey |
validationMaxLength(int maxLength)
Starts the creation of a "maximum length" validation.
|
ValidationBuilderKey |
validationMaxSize(int maxSize,
boolean ignoreNullValues)
Starts the creation of a "maximum size" validation.
|
ValidationBuilderKey |
validationMinLength(int minLength)
Starts the creation of a "minimum length" validation.
|
ValidationBuilderKey |
validationMinSize(int minSize,
boolean ignoreNullValues)
Starts the creation of a "minimum size" validation.
|
ValidationBuilderKey |
validationNotBlank()
Starts the creation of a "not blank" validation.
|
ValidationBuilderKey |
validationNotEquivalent(Object reference)
Starts the creation of a "not equivalent" validation.
|
ValidationBuilderKey |
validationNotNull()
Starts the creation of a "not null" validation.
|
ValidationBuilderKey |
validationNotPattern(String pattern)
Starts the creation of a "pattern must not match" validation.
|
ValidationBuilderKey |
validationNull()
Starts the creation of a "must be null" validation.
|
ValidationBuilderKey |
validationPattern(String pattern)
Starts the creation of a "pattern must match" validation.
|
ValidationBuilderKey |
validationSize(int size,
boolean ignoreNullValues)
Starts the creation of a "size" validation.
|
static final String VALIDATION_CODE_WHOLE_ARRAY_VALIDATION_RESULT_TYPE
static final String VALIDATION_CODE_NOT_AN_ARRAY
static final String VALIDATION_CODE_NOT_NULL
static final String VALIDATION_CODE_NULL
static final String VALIDATION_CODE_NOT_BLANK
static final String VALIDATION_CODE_BLANK
static final String VALIDATION_CODE_EQUIVALENT
static final String VALIDATION_CODE_NOT_EQUIVALENT
static final String VALIDATION_CODE_EQUIVALENT_OR_GREATER
static final String VALIDATION_CODE_GREATER
static final String VALIDATION_CODE_EQUIVALENT_OR_LESS
static final String VALIDATION_CODE_LESS
static final String VALIDATION_CODE_LENGTH
static final String VALIDATION_CODE_MIN_LENGTH
static final String VALIDATION_CODE_MAX_LENGTH
static final String VALIDATION_CODE_PATTERN
static final String VALIDATION_CODE_NOT_PATTERN
static final String VALIDATION_CODE_EMAIL
static final String VALIDATION_CODE_SIZE
static final String VALIDATION_CODE_MIN_SIZE
static final String VALIDATION_CODE_MAX_SIZE
static final String VALIDATION_CODE_CAN_BE_CONVERTED_TO
static final String VALIDATION_CODE_IS_OF_TYPE
ValidationSet createValidationSet()
ValidationSet addMessage(String validationKey, ValidationMessage validationMessage)
ValidationSet addMessage(String validationKey, ValidationLevel messageLevel, String code, String text)
ValidationSet addError(String validationKey, String code, String text)
ValidationSet addWarning(String validationKey, String code, String text)
ValidationSet addSuccess(String validationKey, String code, String text)
ValidationSet mergeValidationSet(ValidationSet set)
ValidationSet mergeValidationSet(String validationKeyPrefix, ValidationSet result)
validationKeyPrefix.boolean hasMessages()
boolean hasMessages(String validationKey)
boolean isWarning()
true if the validation set
contains at least one WARNING message, but no
ERROR messages.boolean isWarning(String validationKey)
true if the validation set
for the element at the specified key contains at
least one WARNING message, but no
ERROR messages.boolean isSuccess()
true if the validation set
only contains SUCCESS messages
(or contains no messages at all).boolean isSuccess(String validationKey)
true if the validation set
for the element at the specified key only contains
SUCCESS messages
(or contains no messages at all).boolean isError()
true if the validation set
contains at least one ERROR message.boolean isError(String validationKey)
true if the validation set
for the element at the specified key contains
at least one ERROR message.boolean isValid()
true if the validation set
does not contain ERROR messages.
The set may contain
WARNING messages.
This is a synonym of !isError().
boolean isValid(String validationKey)
true if the validation set
for the element at the specified key
does not contain ERROR messages.
The element may contains
WARNING messages.
This is a synonym of !isError(key).
Map<String,List<ValidationMessage>> getMessages()
The Map and the lists are immutable.
List<ValidationMessage> getMessages(String validationKey)
The list is immutable.
String getMessagesFormatted(String validationKey, ValidationMessageFormatType formatType)
key - The key to get messages for.formatType - The type of output for the messages (Text, HTML, Json or XML).null if
there are no validation messages.String getMessagesFormatted(ValidationMessageFormatType formatType)
formatType - The type of output for the messages (Text, HTML, Json or XML).null if
there are no validation messages.JsonObject convertToJsonObject()
JsonObject object.
The resulting JsonObject object
is immutable.
convertToJsonObject in interface ToJsonObjectConvertibleValidationBuilderKey validation(SimpleValidator validator)
SimpleValidator.
This is useful when you have a validator that can be reuse in different contexts (as the ones provided by Spincast).
If you need full control over a validation, the number of
generated Messages for example, then you can instead run your
validations as you wish
and use #addMessage(ValidationMessage) and other
similar methods to add the resulting validation Messages to the
set.
ValidationBuilderKey validationNotBlank()
ValidationBuilderKey validationBlank()
ValidationBuilderKey validationEmail()
ValidationBuilderKey validationNotNull()
ValidationBuilderKey validationNull()
ValidationBuilderKey validationPattern(String pattern)
ValidationBuilderKey validationNotPattern(String pattern)
ValidationBuilderKey validationSize(int size, boolean ignoreNullValues)
ignoreNullValues - If true, null values will
be ignored in the total count. For example, if the size validation
is done on a JsonArray which is [null, null "abc"],
the size would be 3 if ignoreNullValues is false
and 1 if it's true.ValidationBuilderKey validationMinSize(int minSize, boolean ignoreNullValues)
ignoreNullValues - If true, null values will
be ignored in the total count. For example, if the size validation
is done on a JsonArray which is [null, null "abc"],
the size would be 3 if ignoreNullValues is false
and 1 if it's true.ValidationBuilderKey validationMaxSize(int maxSize, boolean ignoreNullValues)
ignoreNullValues - If true, null values will
be ignored in the total count. For example, if the size validation
is done on a JsonArray which is [null, null "abc"],
the size would be 3 if ignoreNullValues is false
and 1 if it's true.ValidationBuilderKey validationLength(int length)
ValidationBuilderKey validationMinLength(int minLength)
A null value returns false, otherwise
toString() is called on the other object to
check its "length".
ValidationBuilderKey validationMaxLength(int maxLength)
A null value returns true, otherwise
toString() is called on the other object to
check its "length".
ValidationBuilderKey validationEquivalent(Object reference)
To validate if an element is equivalent to another,
one is converted to the type of the other if this is required.
If this conversion fails, they are not equivalent. When both
elements are of the same types, the #equals(Object)
method is used to compre them.
The exact logic to determine if two elements are equivalent
can be found in ObjectConverter.isEquivalent(Object, Object).
ValidationBuilderKey validationNotEquivalent(Object reference)
To validate if an element is equivalent to another,
one is converted to the type of the other if this is required.
If this conversion fails, they are not equivalent. When both
elements are of the same types, the #equals(Object)
method is used to compre them.
The exact logic to determine if two elements are equivalent
can be found in ObjectConverter.isEquivalent(Object, Object).
ValidationBuilderKey validationLess(Object reference) throws CantCompareException
To validate if an element is less than another,
one is converted to the type of the other if this is required.
If this conversion fails, they can't be compared.
The resulting type must implement the Comparable interface,
so the Comparable.compareTo(Object) method is
used to compare the two elements.
null is always less than a non-null element.
CantCompareException - if the two elements can't be compared
together.ValidationBuilderKey validationGreater(Object reference) throws CantCompareException
To validate if an element is greater than another,
one is converted to the type of the other if this is required.
If this conversion fails, they can't be compared.
The resulting type must implement the Comparable interface,
so the Comparable.compareTo(Object) method is
used to compare the two elements.
null is always less than a non-null element.
CantCompareException - if the two elements can't be compared
together.ValidationBuilderKey validationEquivalentOrLess(Object reference) throws CantCompareException
To validate if an element is equivalent or less than another,
one is converted to the type of the other if this is required.
If this conversion fails, they can't be compared.
The resulting type must implement the Comparable interface,
so the Comparable.compareTo(Object) method is
used to compare the two elements.
null is always less than a non-null element.
CantCompareException - if the two elements can't be compared
together.ValidationBuilderKey validationEquivalentOrGreater(Object reference) throws CantCompareException
To validate if an element is equivalent or greater than another,
one is converted to the type of the other if this is required.
If this conversion fails, they can't be compared.
The resulting type must implement the Comparable interface,
so the Comparable.compareTo(Object) method is
used to compare the two elements.
null is always less than a non-null element.
CantCompareException - if the two elements can't be compared
together.ValidationSet prefixValidationKeys(String prefix)
Copyright © 2016. All rights reserved.