- Type Parameters:
V
- type of the value tovalidate
.
- All Superinterfaces:
Composable<Validator<?>>
,Iterable<Validator<?>>
- All Known Implementing Classes:
AbstractComposedValidator
,AbstractValidator
,AbstractValueValidator
,ComposedValidator
,ProjectionValidator
A
There can be arbitrary implementations of this interface. A regular implementation shall be stateless and therefore thread-safe. All parameterization shall therefore happen on initialization - ideally at construction.
NOTE:
This API intentionally does NOT make use of
ATTENTION:
The
Validator
allows to validate
according values. There can be arbitrary implementations of this interface. A regular implementation shall be stateless and therefore thread-safe. All parameterization shall therefore happen on initialization - ideally at construction.
NOTE:
This API intentionally does NOT make use of
exceptions
as they are more expensive to produce and
shall only occur in exceptional situations, while a validation failure is a regular use-case. Further, a validation
shall validate entire objects to the end collecting all failures
so the end-user can see and
fix all problems at once.ATTENTION:
The
null
values is typically only handled by mandatory validator
. Other validators
will treat null
as a valid value. This design gives the best flexibility as it allows to define specific
constraints also for optional values. However, you need to be aware this fact to avoid mistakes. So e.g. adding a
validator requiring that the minimum size/length of a value needs to be e.g. 2 will still accept null
as
valid. So in such case you most probably want to combine
it with the mandatory validator
.- Since:
- 1.0.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault <T> Validator
<T> default <T> Validator
<T> default boolean
containsId
(String id) default <T> T
getId()
default <T extends Comparable<?>>
TgetMax()
default <T extends Comparable<?>>
TgetMin()
default <T extends Comparable<?>>
Range<T> getRange()
default boolean
static boolean
isValidating
(Validator<?> validator) static <T> Validator
<T> none()
default ValidationResult
This method validates the givenvalue
.This method validates the givenvalue
.Methods inherited from interface io.github.mmm.base.lang.Composable
getChild, getChildCount, iterator
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
ID_MANDATORY
- See Also:
-
-
Method Details
-
validate
This method validates the givenvalue
.- Parameters:
value
- is the value to validate.- Returns:
- the
ValidationResult
ornull
if the givenvalue
is valid according to thisValidator
.
-
validate
This method validates the givenvalue
.- Parameters:
value
- is the value to validate.valueSource
- is thesource
describing the origin of the givenvalue
. The source needs to have a reasonablestring-representation
as this may be displayed to the end-user to locate the source of the failure. In most cases it is suitable to directly pass aString
.- Returns:
- the
ValidationResult
.
-
getId
String getId()- Returns:
- the identifier of this
Validator
. - See Also:
-
isMandatory
default boolean isMandatory()- Returns:
true
if this is a validator for mandatory fields (that will not acceptnull
or empty values),false
otherwise.
-
containsId
-
getChild
-
getRange
- Type Parameters:
T
- type of theRange
value. Typically of type <V> but e.g. forString
orCollection
the type would beInteger
to validate the size of the actual value.- Returns:
- the
Range
constraint with an optionalmimimum
and/ormaximum
value. Will beRange.unbounded()
by if no bounds are validated.
-
getMin
- Type Parameters:
T
- type of the minimum value. Typically of type <V> but e.g. forString
orCollection
the type would beInteger
to validate the size of the actual value.- Returns:
- the minimum allowed value.
-
getMax
- Type Parameters:
T
- type of the minimum value. Typically of type <V> but e.g. forString
orCollection
the type would beInteger
to validate the size of the actual value.- Returns:
- the maximum allowed value.
-
append
-
append
-
none
- Type Parameters:
T
- type of the value tovalidate
.- Returns:
- an instance of
Validator
that always returnValidationResultValid
(accepts any value as valid input).
-
isValidating
-