-
- All Superinterfaces:
Composable<ValidationResult>
,Iterable<ValidationResult>
,Localizable
,LocalizableObject
- All Known Implementing Classes:
AbstractValidationResult
,ComposedValidationFailure
,ValidationFailure
,ValidationResultValid
public interface ValidationResult extends Composable<ValidationResult>, Localizable
Result of avalidation
. Ifvalid
istrue
, themessage
isnull
. Otherwise the message shall be filled and explain the reason of the failure in a understandable but short form to end-users. Examples are "Value may not be blank." or "Value has to be in the range from 5 to 9.". Depending on theusage
the message may also contain additional context information in order to determine the source of the problem.- Since:
- 1.0.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description ValidationResult
add(ValidationResult result)
default boolean
containsCode(String code)
String
getCode()
default String
getLocalizedMessage(boolean verbose)
This method gets the resolved and localized message.default String
getLocalizedMessage(Locale locale, boolean verbose)
This method gets the resolved and localized message.default void
getLocalizedMessage(Locale locale, Appendable buffer)
This method writes thelocalized message
to the givenAppendable
.void
getLocalizedMessage(Locale locale, Appendable buffer, boolean verbose)
default String
getMessage()
ATTENTION:
In most cases you wand to useLocalizable.getLocalizedMessage(Locale)
instead of this method.default String
getMessage(boolean verbose)
String
getSource()
default boolean
isValid()
-
Methods inherited from interface io.github.mmm.base.lang.Composable
getChild, getChildCount, iterator
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface io.github.mmm.base.i18n.Localizable
getArgument, getLocalizedMessage, getLocalizedMessage, toLocalizable
-
-
-
-
Method Detail
-
isValid
default boolean isValid()
- Returns:
true
if the validation was successful,false
otherwise. A successfulValidationResult
is always empty. All other methods will not return any resonable result.
-
getSource
String getSource()
- Returns:
- the optional
validation source
describing the origin of thevalue
that has been validated. May benull
. If present this may be the filename where the value was read from, an XPath where the value was located in an XML document, the label of a widget of the UI containing the value, etc. This will help to find the problem easier.
-
getCode
String getCode()
- Returns:
- the failure code or
null
ifvalid
. For a singleValidationFailure
this will be theID
of the failingValidator
. The code is a stable identifier that indicates the type of the failure. It can be used for automated testing in order to make the test-cases independent from the actual message texts so they are maintainable and will not break e.g. if typos are fixed in the messages. - See Also:
ComposedValidationFailure.CODE
-
getMessage
default String getMessage()
Description copied from interface:Localizable
ATTENTION:
In most cases you wand to useLocalizable.getLocalizedMessage(Locale)
instead of this method.- Specified by:
getMessage
in interfaceLocalizable
- Returns:
- the untranslated message with arguments filled in. This results in the message in its original language that should typically be English.
- See Also:
getMessage(boolean)
-
getMessage
default String getMessage(boolean verbose)
- Parameters:
verbose
-- Returns:
- the localized message.
- See Also:
getMessage()
-
getLocalizedMessage
default String getLocalizedMessage(boolean verbose)
This method gets the resolved and localized message.- Parameters:
verbose
- the verbose flag (to includecode
(s), etc.- Returns:
- the localized message.
-
getLocalizedMessage
default String getLocalizedMessage(Locale locale, boolean verbose)
This method gets the resolved and localized message.
-
getLocalizedMessage
default void getLocalizedMessage(Locale locale, Appendable buffer)
Description copied from interface:Localizable
- Specified by:
getLocalizedMessage
in interfaceLocalizable
- Parameters:
locale
- theLocale
to translate to.buffer
- theAppendable
where towrite
the message to.- See Also:
getLocalizedMessage(Locale, Appendable, boolean)
-
getLocalizedMessage
void getLocalizedMessage(Locale locale, Appendable buffer, boolean verbose)
- Parameters:
locale
- is theLocale
to translate to.buffer
- theAppendable
where towrite
the message to.verbose
- the verbose flag (to includecode
(s), etc.- See Also:
getLocalizedMessage(Locale, Appendable)
-
add
ValidationResult add(ValidationResult result)
- Parameters:
result
- anotherValidationResult
to combine with this one.- Returns:
- the
ValidationResult
composed out of this with the givenresult
. - See Also:
ValidationResultBuilder
-
containsCode
default boolean containsCode(String code)
- Parameters:
code
- thecode
to check for.- Returns:
true
if thisValidationResult
itselfhas
the givencode
or recursivelycontains
suchValidationResult
s,false
otherwise.
-
-