Class Args


  • public class Args
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Args()
      Private constructor so that no instances can be created.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void check​(boolean expression, java.lang.String message)  
      static void check​(boolean expression, java.lang.String message, java.lang.Object arg)  
      static void check​(boolean expression, java.lang.String message, java.lang.Object... args)  
      static long checkContentLength​(EntityDetails entityDetails)
      static int checkRange​(int value, int lowInclusive, int highInclusive, java.lang.String message)  
      static long checkRange​(long value, long lowInclusive, long highInclusive, java.lang.String message)  
      static <T extends java.lang.CharSequence>
      T
      containsNoBlanks​(T argument, java.lang.String name)  
      private static java.lang.IllegalArgumentException illegalArgumentException​(java.lang.String format, java.lang.Object... args)  
      private static java.lang.IllegalArgumentException illegalArgumentExceptionNotEmpty​(java.lang.String name)  
      static boolean isEmpty​(java.lang.Object object)
      Checks if an Object is empty or null.
      static <T extends java.lang.CharSequence>
      T
      notBlank​(T argument, java.lang.String name)  
      static <T extends java.lang.CharSequence>
      T
      notEmpty​(T argument, java.lang.String name)  
      static int notNegative​(int n, java.lang.String name)  
      static long notNegative​(long n, java.lang.String name)  
      static <T> T notNull​(T argument, java.lang.String name)
      Validate that the specified argument is not null; otherwise throwing an exception with the specified message.
      private static java.lang.NullPointerException NullPointerException​(java.lang.String name)  
      static int positive​(int n, java.lang.String name)  
      static long positive​(long n, java.lang.String name)  
      static <T extends TimeValue>
      T
      positive​(T timeValue, java.lang.String name)  
      • Methods inherited from class java.lang.Object

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

      • Args

        private Args()
        Private constructor so that no instances can be created. This class contains only static utility methods.
    • Method Detail

      • check

        public static void check​(boolean expression,
                                 java.lang.String message)
      • check

        public static void check​(boolean expression,
                                 java.lang.String message,
                                 java.lang.Object... args)
      • check

        public static void check​(boolean expression,
                                 java.lang.String message,
                                 java.lang.Object arg)
      • checkRange

        public static int checkRange​(int value,
                                     int lowInclusive,
                                     int highInclusive,
                                     java.lang.String message)
      • checkRange

        public static long checkRange​(long value,
                                      long lowInclusive,
                                      long highInclusive,
                                      java.lang.String message)
      • containsNoBlanks

        public static <T extends java.lang.CharSequence> T containsNoBlanks​(T argument,
                                                                            java.lang.String name)
      • illegalArgumentException

        private static java.lang.IllegalArgumentException illegalArgumentException​(java.lang.String format,
                                                                                   java.lang.Object... args)
      • illegalArgumentExceptionNotEmpty

        private static java.lang.IllegalArgumentException illegalArgumentExceptionNotEmpty​(java.lang.String name)
      • NullPointerException

        private static java.lang.NullPointerException NullPointerException​(java.lang.String name)
      • notBlank

        public static <T extends java.lang.CharSequence> T notBlank​(T argument,
                                                                    java.lang.String name)
      • notEmpty

        public static <T extends java.lang.CharSequence> T notEmpty​(T argument,
                                                                    java.lang.String name)
      • notEmpty

        public static <E,​T extends java.util.Collection<E>> T notEmpty​(T argument,
                                                                             java.lang.String name)
      • notEmpty

        public static <T> T notEmpty​(T argument,
                                     java.lang.String name)
      • notNegative

        public static int notNegative​(int n,
                                      java.lang.String name)
      • notNegative

        public static long notNegative​(long n,
                                       java.lang.String name)
      • notNull

        public static <T> T notNull​(T argument,
                                    java.lang.String name)

        Validate that the specified argument is not null; otherwise throwing an exception with the specified message.

        Args.notNull(myObject, "The object must not be null");
        Type Parameters:
        T - the object type
        Parameters:
        argument - the object to check
        name - the String exception message if invalid, not null
        Returns:
        the validated object (never null for method chaining)
        Throws:
        java.lang.NullPointerException - if the object is null
      • isEmpty

        public static boolean isEmpty​(java.lang.Object object)

        Checks if an Object is empty or null.

        The following types are supported:
        • CharSequence: Considered empty if its length is zero.
        • Array: Considered empty if its length is zero.
        • Collection: Considered empty if it has zero elements.
        • Map: Considered empty if it has zero key-value mappings.
         Args.isEmpty(null)             = true
         Args.isEmpty("")               = true
         Args.isEmpty("ab")             = false
         Args.isEmpty(new int[]{})      = true
         Args.isEmpty(new int[]{1,2,3}) = false
         Args.isEmpty(1234)             = false
         
        Parameters:
        object - the Object to test, may be null
        Returns:
        true if the object has a supported type and is empty or null, false otherwise
        Since:
        5.1
      • positive

        public static int positive​(int n,
                                   java.lang.String name)
      • positive

        public static long positive​(long n,
                                    java.lang.String name)
      • positive

        public static <T extends TimeValue> T positive​(T timeValue,
                                                       java.lang.String name)