Class ObjectUtil

java.lang.Object
io.netty.util.internal.ObjectUtil

public final class ObjectUtil extends java.lang.Object
A grab-bag of useful utility methods.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final double
     
    private static final float
     
    private static final int
     
    private static final long
     
    private static final short
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    checkInRange(double d, double start, double end, java.lang.String name)
    Checks that the given argument is in range.
    static int
    checkInRange(int i, int start, int end, java.lang.String name)
    Checks that the given argument is in range.
    static long
    checkInRange(long l, long start, long end, java.lang.String name)
    Checks that the given argument is in range.
    static byte[]
    checkNonEmpty(byte[] array, java.lang.String name)
    Checks that the given argument is neither null nor empty.
    static char[]
    checkNonEmpty(char[] array, java.lang.String name)
    Checks that the given argument is neither null nor empty.
    static java.lang.CharSequence
    checkNonEmpty(java.lang.CharSequence value, java.lang.String name)
    Checks that the given argument is neither null nor empty.
    static java.lang.String
    checkNonEmpty(java.lang.String value, java.lang.String name)
    Checks that the given argument is neither null nor empty.
    static <T> T[]
    checkNonEmpty(T[] array, java.lang.String name)
    Checks that the given argument is neither null nor empty.
    static <K, V, T extends java.util.Map<K,V>>
    T
    checkNonEmpty(T value, java.lang.String name)
    Checks that the given argument is neither null nor empty.
    static <T extends java.util.Collection<?>>
    T
    checkNonEmpty(T collection, java.lang.String name)
    Checks that the given argument is neither null nor empty.
    static java.lang.String
    checkNonEmptyAfterTrim(java.lang.String value, java.lang.String name)
    Trims the given argument and checks whether it is neither null nor empty.
    static <T> T
    checkNotNull(T arg, java.lang.String text)
    Checks that the given argument is not null.
    static <T> T
    checkNotNullArrayParam(T value, int index, java.lang.String name)
    Checks that the given argument is not null.
    static <T> T
    checkNotNullWithIAE(T arg, java.lang.String paramName)
    Checks that the given argument is not null.
    static double
    checkPositive(double d, java.lang.String name)
    Checks that the given argument is strictly positive.
    static float
    checkPositive(float f, java.lang.String name)
    Checks that the given argument is strictly positive.
    static int
    checkPositive(int i, java.lang.String name)
    Checks that the given argument is strictly positive.
    static long
    checkPositive(long l, java.lang.String name)
    Checks that the given argument is strictly positive.
    static short
    checkPositive(short s, java.lang.String name)
    Checks that the given argument is positive or zero.
    static double
    checkPositiveOrZero(double d, java.lang.String name)
    Checks that the given argument is positive or zero.
    static float
    checkPositiveOrZero(float f, java.lang.String name)
    Checks that the given argument is positive or zero.
    static int
    checkPositiveOrZero(int i, java.lang.String name)
    Checks that the given argument is positive or zero.
    static long
    checkPositiveOrZero(long l, java.lang.String name)
    Checks that the given argument is positive or zero.
    static <T> T[]
    deepCheckNotNull(java.lang.String text, T... varargs)
    Check that the given varargs is not null and does not contain elements null elements.
    static int
    intValue(java.lang.Integer wrapper, int defaultValue)
    Resolves a possibly null Integer to a primitive int, using a default value.
    static long
    longValue(java.lang.Long wrapper, long defaultValue)
    Resolves a possibly null Long to a primitive long, using a default value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ObjectUtil

      private ObjectUtil()
  • Method Details

    • checkNotNull

      public static <T> T checkNotNull(T arg, java.lang.String text)
      Checks that the given argument is not null. If it is, throws NullPointerException. Otherwise, returns the argument.
    • deepCheckNotNull

      public static <T> T[] deepCheckNotNull(java.lang.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.
    • checkNotNullWithIAE

      public static <T> T checkNotNullWithIAE(T arg, java.lang.String paramName) throws java.lang.IllegalArgumentException
      Checks that the given argument is not null. If it is, throws IllegalArgumentException. Otherwise, returns the argument.
      Throws:
      java.lang.IllegalArgumentException
    • checkNotNullArrayParam

      public static <T> T checkNotNullArrayParam(T value, int index, java.lang.String name) throws java.lang.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:
      value - to check.
      index - of the array, belongs to the exception message.
      name - of the parameter, belongs to the exception message.
      Returns:
      the given argument value.
      Throws:
      java.lang.IllegalArgumentException - if value is null.
    • checkPositive

      public static int checkPositive(int i, java.lang.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, java.lang.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, java.lang.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, java.lang.String name)
      Checks that the given argument is strictly positive. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.
    • checkPositive

      public static short checkPositive(short s, java.lang.String name)
      Checks that the given argument is positive or zero. If it is not , throws IllegalArgumentException. Otherwise, returns the argument.
    • checkPositiveOrZero

      public static int checkPositiveOrZero(int i, java.lang.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, java.lang.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, java.lang.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, java.lang.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, java.lang.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, java.lang.String name)
      Checks that the given argument is in range. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.
    • checkInRange

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

      public static <T> T[] checkNonEmpty(T[] array, java.lang.String name)
      Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.
    • checkNonEmpty

      public static byte[] checkNonEmpty(byte[] array, java.lang.String name)
      Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.
    • checkNonEmpty

      public static char[] checkNonEmpty(char[] array, java.lang.String name)
      Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.
    • checkNonEmpty

      public static <T extends java.util.Collection<?>> T checkNonEmpty(T collection, java.lang.String name)
      Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.
    • checkNonEmpty

      public static java.lang.String checkNonEmpty(java.lang.String value, java.lang.String name)
      Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.
    • checkNonEmpty

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

      public static java.lang.CharSequence checkNonEmpty(java.lang.CharSequence value, java.lang.String name)
      Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.
    • checkNonEmptyAfterTrim

      public static java.lang.String checkNonEmptyAfterTrim(java.lang.String value, java.lang.String name)
      Trims the given argument and checks whether it is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the trimmed argument.
      Parameters:
      value - to trim and check.
      name - of the parameter.
      Returns:
      the trimmed (not the original) value.
      Throws:
      java.lang.NullPointerException - if value is null.
      java.lang.IllegalArgumentException - if the trimmed value is empty.
    • intValue

      public static int intValue(java.lang.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(java.lang.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