Class ObjectUtil


  • public final class ObjectUtil
    extends Object
    A grab-bag of useful utility methods.
    • Method Detail

      • deepCheckNotNull

        public static <T> T[] deepCheckNotNull​(String text,
                                               T... varargs)
        Check that the given varargs is not null and does not contain elements null elements. If it is, throws NullPointerException. Otherwise, returns the argument.
      • checkNotNullArrayParam

        public static <T> T checkNotNullArrayParam​(T value,
                                                   int index,
                                                   String name)
                                            throws IllegalArgumentException
        Checks that the given argument is not null. If it is, throws IllegalArgumentException. Otherwise, returns the argument.
        Type Parameters:
        T - type of the given argument value.
        Parameters:
        name - of the parameter, belongs to the exception message.
        index - of the array, belongs to the exception message.
        value - to check.
        Returns:
        the given argument value.
        Throws:
        IllegalArgumentException - if value is null.
      • checkPositive

        public static int checkPositive​(int i,
                                        String name)
        Checks that the given argument is strictly positive. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.
      • checkPositive

        public static long checkPositive​(long l,
                                         String name)
        Checks that the given argument is strictly positive. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.
      • checkPositive

        public static double checkPositive​(double d,
                                           String name)
        Checks that the given argument is strictly positive. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.
      • checkPositive

        public static float checkPositive​(float f,
                                          String name)
        Checks that the given argument is strictly positive. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.
      • checkPositiveOrZero

        public static int checkPositiveOrZero​(int i,
                                              String name)
        Checks that the given argument is positive or zero. If it is not , throws IllegalArgumentException. Otherwise, returns the argument.
      • checkPositiveOrZero

        public static long checkPositiveOrZero​(long l,
                                               String name)
        Checks that the given argument is positive or zero. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.
      • checkPositiveOrZero

        public static double checkPositiveOrZero​(double d,
                                                 String name)
        Checks that the given argument is positive or zero. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.
      • checkPositiveOrZero

        public static float checkPositiveOrZero​(float f,
                                                String name)
        Checks that the given argument is positive or zero. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.
      • checkInRange

        public static int checkInRange​(int i,
                                       int start,
                                       int end,
                                       String name)
        Checks that the given argument is in range. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.
      • checkInRange

        public static long checkInRange​(long l,
                                        long start,
                                        long end,
                                        String name)
        Checks that the given argument is in range. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.
      • checkNonEmpty

        public static <K,​V,​T extends Map<K,​V>> T checkNonEmpty​(T value,
                                                                                 String name)
        Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.
      • intValue

        public static int intValue​(Integer wrapper,
                                   int defaultValue)
        Resolves a possibly null Integer to a primitive int, using a default value.
        Parameters:
        wrapper - the wrapper
        defaultValue - the default value
        Returns:
        the primitive value
      • longValue

        public static long longValue​(Long wrapper,
                                     long defaultValue)
        Resolves a possibly null Long to a primitive long, using a default value.
        Parameters:
        wrapper - the wrapper
        defaultValue - the default value
        Returns:
        the primitive value