Class ArgumentUtils


  • public class ArgumentUtils
    extends java.lang.Object
    Utility methods for checking method argument values.
    Since:
    1.0
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ArgumentUtils

        public ArgumentUtils()
    • 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 argument
        value - 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 argument
        value - 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 argument
        value - The value
        Returns:
        The value
        Throws:
        java.lang.IllegalArgumentException - if the argument is not positive
      • 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 argument
        value - 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 instance
        arguments - The arguments
        values - The values