Package io.smallrye.mutiny.helpers
Class ParameterValidation
- java.lang.Object
-
- io.smallrye.mutiny.helpers.ParameterValidation
-
public class ParameterValidation extends java.lang.Object
A class to validate method parameters. these methods throwIllegalArgumentException
is the validation fails.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
MAPPER_RETURNED_NULL
static java.lang.String
SUPPLIER_PRODUCED_NULL
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T[]
doesNotContainNull(T[] array, java.lang.String name)
Ensures that the given array does not contain anull
value.static <T extends java.lang.Iterable<?>>
TdoesNotContainNull(T iterable, java.lang.String name)
Ensures that the given iterable does not contain anull
value.static <T extends java.util.Collection<?>>
TisNotEmpty(T collection, java.lang.String name)
Ensures that the given cllection is not empty.static <T> T
nonNull(T instance, java.lang.String name)
Validates that the giveninstance
is notnull
.static <T> T
nonNullNpe(T instance, java.lang.String name)
Validates that the giveninstance
is notnull
.static int
positive(int amount, java.lang.String name)
Validates that the passed amount is strictly positive.static long
positive(long amount, java.lang.String name)
Validates that the passed amount is strictly positive.static int
positiveOrZero(int amount, java.lang.String name)
Validates that the passed amount is positive (including 0).static long
positiveOrZero(long amount, java.lang.String name)
Validates that the passed amount is positive (including 0).static <T extends java.util.Collection<?>>
Tsize(T instance, int expectedSize, java.lang.String name)
Validates that the given collectioninstance
has size matching theexpectedSize
static java.time.Duration
validate(java.time.Duration duration, java.lang.String name)
Validates that the passed duration is notnull
and strictly positive.
-
-
-
Field Detail
-
SUPPLIER_PRODUCED_NULL
public static final java.lang.String SUPPLIER_PRODUCED_NULL
- See Also:
- Constant Field Values
-
MAPPER_RETURNED_NULL
public static final java.lang.String MAPPER_RETURNED_NULL
- See Also:
- Constant Field Values
-
-
Method Detail
-
validate
public static java.time.Duration validate(java.time.Duration duration, java.lang.String name)
Validates that the passed duration is notnull
and strictly positive.- Parameters:
duration
- the durationname
- the name of the parameter, must not benull
- Returns:
- the duration is the validation passes.
-
nonNull
public static <T> T nonNull(T instance, java.lang.String name)
Validates that the giveninstance
is notnull
.- Type Parameters:
T
- the type of the instance- Parameters:
instance
- the instancename
- the name of the parameter, must not benull
- Returns:
- the instance if the validation passes
-
nonNullNpe
public static <T> T nonNullNpe(T instance, java.lang.String name)
Validates that the giveninstance
is notnull
. UnlikenonNull(Object, String)
, this method throw aNullPointerException
. It's generally used to be compliant with the Reactive Streams specification expectingNullPointerException
.- Type Parameters:
T
- the type of the instance- Parameters:
instance
- the instancename
- the name of the parameter, must not benull
- Returns:
- the instance if the validation passes
-
positive
public static long positive(long amount, java.lang.String name)
Validates that the passed amount is strictly positive.- Parameters:
amount
- the amount to be checkedname
- the name of the parameter, must not benull
- Returns:
- the amount is the validation passes.
-
positive
public static int positive(int amount, java.lang.String name)
Validates that the passed amount is strictly positive.- Parameters:
amount
- the amount to be checkedname
- the name of the parameter, must not benull
- Returns:
- the amount is the validation passes.
-
positiveOrZero
public static int positiveOrZero(int amount, java.lang.String name)
Validates that the passed amount is positive (including 0).- Parameters:
amount
- the amount to be checkedname
- the name of the parameter, must not benull
- Returns:
- the amount is the validation passes.
-
positiveOrZero
public static long positiveOrZero(long amount, java.lang.String name)
Validates that the passed amount is positive (including 0).- Parameters:
amount
- the amount to be checkedname
- the name of the parameter, must not benull
- Returns:
- the amount is the validation passes.
-
doesNotContainNull
public static <T extends java.lang.Iterable<?>> T doesNotContainNull(T iterable, java.lang.String name)
Ensures that the given iterable does not contain anull
value.- Type Parameters:
T
- the type of the instance- Parameters:
iterable
- the iterablename
- the name of the parameter, must not benull
- Returns:
- the instance if the validation passes
-
doesNotContainNull
public static <T> T[] doesNotContainNull(T[] array, java.lang.String name)
Ensures that the given array does not contain anull
value.- Type Parameters:
T
- the type of the item contained in the array- Parameters:
array
- the arrayname
- the name of the parameter, must not benull
- Returns:
- the instance if the validation passes
-
isNotEmpty
public static <T extends java.util.Collection<?>> T isNotEmpty(T collection, java.lang.String name)
Ensures that the given cllection is not empty.- Type Parameters:
T
- the type of the item contained in the array- Parameters:
collection
- the collection to checkname
- the name of the parameter, must not benull
- Returns:
- the instance if the validation passes
-
size
public static <T extends java.util.Collection<?>> T size(T instance, int expectedSize, java.lang.String name)
Validates that the given collectioninstance
has size matching theexpectedSize
- Type Parameters:
T
- the type of the instance- Parameters:
instance
- the instanceexpectedSize
- the expected sizename
- the name of the parameter, must not benull
- Returns:
- the instance if the validation passes
-
-