Interface OptionalValidator<T>
- Type Parameters:
T
- the type of object in the optional
- All Superinterfaces:
ObjectComponent<OptionalValidator<T>,
,Optional<T>> ValidatorComponent<OptionalValidator<T>,
Optional<T>>
public interface OptionalValidator<T>
extends ValidatorComponent<OptionalValidator<T>,Optional<T>>, ObjectComponent<OptionalValidator<T>,Optional<T>>
Validates the state of an
Optional
.-
Method Summary
Modifier and TypeMethodDescriptionEnsures that the optional contains a value.Ensures that the optional containsexpected
.isEmpty()
Ensures that the optional is absent.Ensures that the optional contains a value.Methods declared in interface com.github.cowwoc.requirements10.java.validator.component.ObjectComponent
getValue, isEqualTo, isEqualTo, isInstanceOf, isInstanceOf, isNotEqualTo, isNotEqualTo, isNotInstanceOf, isNotInstanceOf, isNotNull, isNull, isReferenceEqualTo, isReferenceNotEqualTo
Methods declared in interface com.github.cowwoc.requirements10.java.validator.component.ValidatorComponent
and, elseGetFailures, elseThrow, getContext, getContextAsString, getName, getValueOrDefault, validationFailed, withContext
-
Method Details
-
isPresent
OptionalValidator<T> isPresent()Ensures that the optional contains a value.- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the optional is empty
-
isEmpty
OptionalValidator<T> isEmpty()Ensures that the optional is absent.- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the optional contains a value
-
contains
Ensures that the optional contains a value.- Parameters:
expected
- the expected value;null
matches an empty optional- Returns:
- this
- Throws:
NullPointerException
- if the value is nullIllegalArgumentException
- if the optional does not containexpected
-
contains
Ensures that the optional containsexpected
.- Parameters:
expected
- the expected value (null
matches an empty optional)name
- the name of the expected value- Returns:
- this
- Throws:
NullPointerException
- if the value orname
are nullIllegalArgumentException
- if:name
is emptyname
contains whitespacename
is already in use by the value being validated or the validator context- the optional does not contain
expected
-