Interface ObjectComponent<S,T>
- Type Parameters:
S
- the type of this validatorT
- the type of the value that is being validated
- All Known Subinterfaces:
BigDecimalValidator
,BigIntegerValidator
,BooleanValidator
,ByteArrayValidator
,ByteValidator
,CharacterValidator
,CollectionValidator<T,
,E> ComparableValidator<T>
,DoubleValidator
,FloatValidator
,GenericTypeValidator<T>
,InetAddressValidator
,IntegerValidator
,JsonNodeValidator<T>
,ListValidator<T,
,E> LongValidator
,MapValidator<T,
,K, V> MultimapValidator<T,
,K, V> ObjectArrayValidator<T,
,E> ObjectValidator<T>
,OptionalValidator<T>
,PathValidator
,PrimitiveBooleanArrayValidator
,PrimitiveByteArrayValidator
,PrimitiveCharacterArrayValidator
,PrimitiveDoubleArrayValidator
,PrimitiveFloatArrayValidator
,PrimitiveIntegerArrayValidator
,PrimitiveLongArrayValidator
,PrimitiveShortArrayValidator
,ShortValidator
,StringValidator
,UnsignedIntegerValidator
,UriValidator
public interface ObjectComponent<S,T>
Methods that all object validators must contain.
-
Method Summary
Modifier and TypeMethodDescriptiongetValue()
Returns the value that is being validated.Ensures that the object is equal toexpected
.Ensures that the object is equal toexpected
.<U> ObjectValidator
<U> isInstanceOf
(GenericType<U> expected) Ensures that the object is an instance of a class.<U> ObjectValidator
<U> isInstanceOf
(Class<U> expected) Ensures that the object is an instance of a class.isNotEqualTo
(Object unwanted) Ensures that the object is not equal tounwanted
.isNotEqualTo
(Object unwanted, String name) Ensures that the object is not equal tounwanted
.isNotInstanceOf
(GenericType<?> unwanted) Ensures that the object is not an instance of a class.isNotInstanceOf
(Class<?> unwanted) Ensures that the object is not an instance of a class.Ensures that the value is not null.isNull()
Ensures that the value isnull
.isReferenceEqualTo
(Object expected, String name) Ensures that the value is the same referenceexpected
.isReferenceNotEqualTo
(Object unwanted, String name) Ensures that the value is not the same reference asunwanted
.
-
Method Details
-
getValue
T getValue()Returns the value that is being validated.- Returns:
- the value
- Throws:
IllegalStateException
- if a previous validation failed
-
isNull
S isNull()Ensures that the value isnull
.- Returns:
- this
- Throws:
IllegalArgumentException
- if the value is not null
-
isNotNull
S isNotNull()Ensures that the value is not null.This method should be used to validate method arguments that are assigned to class fields but not accessed right away (such as constructor and setter arguments). It should also be used to validate any method arguments when the validator contains
additional contextual information
. Otherwise, the default Java handler is preferable because it throwsNullPointerException
with a helpful message.- Returns:
- this
- Throws:
NullPointerException
- if the value isnull
-
isReferenceEqualTo
Ensures that the value is the same referenceexpected
.- Parameters:
expected
- the expected objectname
- the name of the expected object- Returns:
- this
- Throws:
NullPointerException
- ifname
isnull
IllegalArgumentException
- if:name
is emptyname
contains whitespacename
is already in use by the value being validated or the validator context- the value does not reference the same value as
expected
-
isReferenceNotEqualTo
Ensures that the value is not the same reference asunwanted
.- Parameters:
unwanted
- the unwanted objectname
- the name of the unwanted object- Returns:
- this
- Throws:
NullPointerException
- ifname
isnull
IllegalArgumentException
- if:name
is emptyname
contains whitespacename
is already in use by the value being validated or the validator context- the value references the same value as
unwanted
-
isInstanceOf
Ensures that the object is an instance of a class.- Type Parameters:
U
- the desired class- Parameters:
expected
- the desired class. For types that contain type-parameters, use theTypeToken
overload.- Returns:
- a validator for an object of the desired class
- Throws:
NullPointerException
- if the value orexpected
are nullIllegalArgumentException
- if the value is not an instance of the desired class
-
isInstanceOf
Ensures that the object is an instance of a class.- Type Parameters:
U
- the desired class- Parameters:
expected
- the desired class. For types without type-parameters, prefer theClass
overload.- Returns:
- a validator for an object of the desired class
- Throws:
NullPointerException
- if the value orexpected
are nullIllegalArgumentException
- if the value is not an instance of the desired class
-
isNotInstanceOf
Ensures that the object is not an instance of a class.- Parameters:
unwanted
- the unwanted class. For types that contain type-parameters, use theTypeToken
overload.- Returns:
- this
- Throws:
NullPointerException
- if the value orunwanted
are nullIllegalArgumentException
- if the value is an instance of the unwanted class
-
isNotInstanceOf
Ensures that the object is not an instance of a class.- Parameters:
unwanted
- the unwanted class. For types without type-parameters, prefer theClass
overload.- Returns:
- this
- Throws:
NullPointerException
- if the value orunwanted
are nullIllegalArgumentException
- if the value is an instance of the unwanted class
-
isEqualTo
Ensures that the object is equal toexpected
.- Parameters:
expected
- the expected value- Returns:
- this
- Throws:
IllegalArgumentException
- if the value is not equal toexpected
- See Also:
-
isEqualTo
Ensures that the object is equal toexpected
.- Parameters:
expected
- the expected valuename
- the name of the expected value- Returns:
- this
- Throws:
NullPointerException
- ifname
isnull
IllegalArgumentException
- if:name
is emptyname
contains whitespacename
is already in use by the value being validated or the validator context- the value is not equal to
expected
- See Also:
-
isNotEqualTo
Ensures that the object is not equal tounwanted
.- Parameters:
unwanted
- the unwanted value- Returns:
- this
- Throws:
IllegalArgumentException
- if the value is equal toexpected
- See Also:
-
isNotEqualTo
Ensures that the object is not equal tounwanted
.- Parameters:
unwanted
- the unwanted valuename
- the name of the other value- Returns:
- this
- Throws:
NullPointerException
- ifname
isnull
IllegalArgumentException
- if:name
is emptyname
contains whitespacename
is already in use by the value being validated or the validator context- the value is equal to the
unwanted
value
- See Also:
-