public final class DefaultValidationResult extends Object implements ValidationResult
A default implementation of the ValidationResult
interface.
Instances of this class store a collection of validation error messages. If
no messages exist with a ValidationMessageLevel
of ERROR
, the
validation result is considered to be valid. It may contain other messages
which are only warning messages.
Clients do not create instances directly through the constructor, but use the
nested Builder
class. Once a builder is created, an arbitrary number
of validation error messages can be added. If all messages have been added,
the build()
method creates an immutable instance of
DefaultValidationResult
. This has the advantage that all fields of
DefaultValidationResult
can be made final. Therefore objects of this
class are thread-safe (note that is not true for the Builder
objects).
There is also a constant representing a validation result for a successful validation. This field can be used in custom validator implementations rather than creating a new instance of this class.
Modifier and Type | Class and Description |
---|---|
static class |
DefaultValidationResult.Builder
A builder class for creating instances of
DefaultValidationResult . |
Modifier and Type | Field and Description |
---|---|
static ValidationResult |
VALID
Constant for a validation result object for a successful validation.
|
Modifier and Type | Method and Description |
---|---|
static ValidationResult |
createValidationErrorResult(TransformerContext context,
String key,
Object... params)
Creates a
ValidationResult object with the specified error
message. |
static ValidationMessage |
createValidationMessage(TransformerContext context,
String key,
Object... params)
Creates a
ValidationMessage object for the specified error
message. |
boolean |
equals(Object obj)
Compares this object to another one.
|
Collection<ValidationMessage> |
getValidationMessages()
Returns an unmodifiable collection with error messages.
|
Collection<ValidationMessage> |
getValidationMessages(ValidationMessageLevel level)
Returns an unmodifiable collection with the
ValidationMessage
objects with the specified ValidationMessageLevel . |
int |
hashCode()
Returns a hash code for this object.
|
boolean |
hasMessages(ValidationMessageLevel level)
Returns a flag whether messages of the specified level are available.
|
boolean |
isValid()
Returns a flag whether the validation was successful.
|
static ValidationResult |
merge(ValidationResult vr1,
ValidationResult vr2)
Combines two validation result objects to a combined result.
|
String |
toString()
Returns a string representation for this object.
|
public static final ValidationResult VALID
public boolean isValid()
isValid
in interface ValidationResult
public Collection<ValidationMessage> getValidationMessages()
getValidationMessages
in interface ValidationResult
public Collection<ValidationMessage> getValidationMessages(ValidationMessageLevel level)
ValidationMessage
objects with the specified ValidationMessageLevel
.getValidationMessages
in interface ValidationResult
level
- the ValidationMessageLevel
public boolean hasMessages(ValidationMessageLevel level)
hasMessages
in interface ValidationResult
level
- the ValidationMessageLevel
in questionpublic boolean equals(Object obj)
public int hashCode()
public String toString()
public static ValidationResult merge(ValidationResult vr1, ValidationResult vr2)
ValidationResult
object is created only if necessary: If one of
the arguments is valid and has no warning messages, the other argument is
returned. The same is true for null arguments. This method returns
null only if both arguments are null.vr1
- the first validation result objectvr2
- the second validation result objectpublic static ValidationMessage createValidationMessage(TransformerContext context, String key, Object... params)
ValidationMessage
object for the specified error
message. This is a convenience method that obtains the
ValidationMessageHandler
from the TransformerContext
and
obtains a ValidationMessage
for the specified parameters.context
- the TransformerContext
(must not be null)key
- the key of the error messageparams
- optional parameters for the error messageValidationResult
object with the specified messageIllegalArgumentException
- if the TransformerContext
is
nullpublic static ValidationResult createValidationErrorResult(TransformerContext context, String key, Object... params)
ValidationResult
object with the specified error
message. This is a convenience method for the frequent case that a
ValidationResult
object with exactly one error message has to be
created. It obtains the ValidationMessageHandler
from the TransformerContext
, obtains a ValidationMessage
for the
specified parameters, and creates a ValidationResult
object with
exactly this message.context
- the TransformerContext
(must not be null)key
- the key of the error messageparams
- optional parameters for the error messageValidationResult
object with this error messageIllegalArgumentException
- if the TransformerContext
is
nullCopyright © 2016 The JGUIraffe Team. All rights reserved.