public class ValidatorUtils
extends java.lang.Object
Constructor and Description |
---|
ValidatorUtils() |
Modifier and Type | Method and Description |
---|---|
<T,R> Validator<T> |
as(java.lang.Class<T> t,
Validator<R> v)
Will do the following:
Check if
t is equal to or assignable to this Validator's
model type. |
static <T,R> Validator<T> |
cast(java.lang.Class<T> type,
Validator<R> other)
Get a validator for a validator of a possibly unknown type.
|
static <T> Validator<T> |
limitSeverity(Severity maximum,
Validator<T>... validators)
Wrapper one or more validators in a validator which imposes a limit on
the severity of the validators in use.
|
static <T> Validator<T> |
limitSeverity(Severity maximum,
Validator<T> validator)
Wraps a validator in a validator which imposes a limit on the severity of the validator in use.
|
static <T> Validator<T> |
merge(Validator<T>... validators)
Merge together a chain of validators (all working which work against the same
type), using logical
AND . |
static <T> Validator<T> |
merge(Validator<T> validator1,
Validator<T> validator2)
Merge together two validators (both of which work against the same type), using logical
AND . |
public static <T> Validator<T> merge(Validator<T>... validators)
AND
. The resulting validator reports success if all the merged validators
report success. (If one or more of the merged validators report failure, the resulting
merged validator reports failure.)T
- The type of model (Document, String, etc.) you want to
work withvalidators
- A chain of validators which should be logically
AND'd together, merged into a single validatorpublic static <T> Validator<T> merge(Validator<T> validator1, Validator<T> validator2)
AND
.
The resulting validator reports success if both the merged validators
report success. (If one or both of the merged validators report failure, the resulting
merged validator reports failure.)
Unlike merge(Validator...)
, calling this method does not trigger warnings under -Xlint:unchecked
.
If you wish to merge more than two validators, simply merge the result of merging two with the next one.
T
- The type of model (Document, String, etc.) you want to
work withvalidator1
- one validatorvalidator2
- another validator of the same typepublic static <T> Validator<T> limitSeverity(Severity maximum, Validator<T>... validators)
T
- The typemaximum
- validators
- public static <T> Validator<T> limitSeverity(Severity maximum, Validator<T> validator)
Unlike limitSeverity(Severity,Validator...)
, calling this method does not trigger warnings under -Xlint:unchecked
.
If you wish to limit more than one validator, simply limit the result of merge(Validator,Validator)
.
T
- The typemaximum
- validator
- public static <T,R> Validator<T> cast(java.lang.Class<T> type, Validator<R> other)
modelType()
.
This method exists principally to avoid compile-time warnings for cases
where a validator type is not actually known at compile time. Most
client code will use a specific type; this technique is mainly
used for cases of factories for validators against multiple types,
whose types cannot be determined at compile-time.
T
- The type parameter of the desired validatorR
- The type of the actual validatortype
- The model type of the desired validatorother
- A validator whose type should be a supertype or the same as
the passed type
argumentpublic final <T,R> Validator<T> as(java.lang.Class<T> t, Validator<R> v)
t
is equal to or assignable to this Validator's
model type. If so, will return an adapter which casts this Validator
as that type.
Converter
that acts as
a factory for Validators of the passed type from Validators of this type
(e.g. produce a Validator for a javax.swing.text.Document
from a
Validator for a java.lang.String
).
If one is found, use that to manufacture a wrapper validator for this
one, which converts arguments appropriately.T
- t
- java.lang.IllegalArgumentException
- if no way is known to either cast
or adapt this validator's model type to the requested one