Package io.micronaut.core.util
Class ArgumentUtils
- java.lang.Object
-
- io.micronaut.core.util.ArgumentUtils
-
public class ArgumentUtils extends java.lang.Object
Utility methods for checking method argument values.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ArgumentUtils.ArgumentCheck<T>
Allows producing error messages.static interface
ArgumentUtils.Check
Functional interface the check a condition.
-
Constructor Summary
Constructors Constructor Description ArgumentUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ArgumentUtils.ArgumentCheck
check(ArgumentUtils.Check check)
Perform a check on an argument.static <T> ArgumentUtils.ArgumentCheck
check(java.lang.String name, T value)
Perform a check on an argument.static <T> T
requireNonNull(java.lang.String name, T value)
Adds a check that the given number is not null.static int
requirePositive(java.lang.String name, int value)
Adds a check that the given number is positive.static java.lang.Number
requirePositive(java.lang.String name, java.lang.Number value)
Adds a check that the given number is positive.static void
validateArguments(Described described, Argument<?>[] arguments, java.lang.Object[] values)
Validates the given values are appropriate for the given arguments.
-
-
-
Method Detail
-
requirePositive
@NonNull public static java.lang.Number requirePositive(java.lang.String name, java.lang.Number value)
Adds a check that the given number is positive.- Parameters:
name
- The name of the argumentvalue
- The value- Returns:
- The value
- Throws:
java.lang.IllegalArgumentException
- if the argument is not positive
-
requireNonNull
public static <T> T requireNonNull(java.lang.String name, T value)
Adds a check that the given number is not null.- Type Parameters:
T
- The generic type- Parameters:
name
- The name of the argumentvalue
- The value- Returns:
- The value
- Throws:
java.lang.NullPointerException
- if the argument is null
-
requirePositive
public static int requirePositive(java.lang.String name, int value)
Adds a check that the given number is positive.- Parameters:
name
- The name of the argumentvalue
- The value- Returns:
- The value
- Throws:
java.lang.IllegalArgumentException
- if the argument is not positive
-
check
public static ArgumentUtils.ArgumentCheck check(ArgumentUtils.Check check)
Perform a check on an argument.- Parameters:
check
- The check- Returns:
- The
ArgumentUtils.ArgumentCheck
-
check
public static <T> ArgumentUtils.ArgumentCheck check(java.lang.String name, T value)
Perform a check on an argument.- Type Parameters:
T
- The value type- Parameters:
name
- The name of the argumentvalue
- The value of the argument- Returns:
- The
ArgumentUtils.ArgumentCheck
-
validateArguments
public static void validateArguments(@NonNull Described described, @NonNull Argument<?>[] arguments, @NonNull java.lang.Object[] values)
Validates the given values are appropriate for the given arguments.- Parameters:
described
- The described instancearguments
- The argumentsvalues
- The values
-
-