Class ObjectUtil
java.lang.Object
io.netty.util.internal.ObjectUtil
A grab-bag of useful utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublecheckInRange(double d, double start, double end, String name) Checks that the given argument is in range.static intcheckInRange(int i, int start, int end, String name) Checks that the given argument is in range.static longcheckInRange(long l, long start, long end, String name) Checks that the given argument is in range.static byte[]checkNonEmpty(byte[] array, String name) Checks that the given argument is neither null nor empty.static char[]checkNonEmpty(char[] array, String name) Checks that the given argument is neither null nor empty.static CharSequencecheckNonEmpty(CharSequence value, String name) Checks that the given argument is neither null nor empty.static StringcheckNonEmpty(String value, String name) Checks that the given argument is neither null nor empty.static <T> T[]checkNonEmpty(T[] array, String name) Checks that the given argument is neither null nor empty.static <K, V, T extends Map<K,V>>
TcheckNonEmpty(T value, String name) Checks that the given argument is neither null nor empty.static <T extends Collection<?>>
TcheckNonEmpty(T collection, String name) Checks that the given argument is neither null nor empty.static StringcheckNonEmptyAfterTrim(String value, String name) Trims the given argument and checks whether it is neither null nor empty.static <T> TcheckNotNull(T arg, String text) Checks that the given argument is not null.static <T> TcheckNotNullArrayParam(T value, int index, String name) Checks that the given argument is not null.static <T> TcheckNotNullWithIAE(T arg, String paramName) Checks that the given argument is not null.static doublecheckPositive(double d, String name) Checks that the given argument is strictly positive.static floatcheckPositive(float f, String name) Checks that the given argument is strictly positive.static intcheckPositive(int i, String name) Checks that the given argument is strictly positive.static longcheckPositive(long l, String name) Checks that the given argument is strictly positive.static shortcheckPositive(short s, String name) Checks that the given argument is positive or zero.static doublecheckPositiveOrZero(double d, String name) Checks that the given argument is positive or zero.static floatcheckPositiveOrZero(float f, String name) Checks that the given argument is positive or zero.static intcheckPositiveOrZero(int i, String name) Checks that the given argument is positive or zero.static longcheckPositiveOrZero(long l, String name) Checks that the given argument is positive or zero.static <T> T[]deepCheckNotNull(String text, T... varargs) Check that the given varargs is not null and does not contain elements null elements.static intResolves a possibly null Integer to a primitive int, using a default value.static longResolves a possibly null Long to a primitive long, using a default value.
-
Method Details
-
checkNotNull
Checks that the given argument is not null. If it is, throwsNullPointerException. Otherwise, returns the argument. -
deepCheckNotNull
Check that the given varargs is not null and does not contain elements null elements. If it is, throwsNullPointerException. Otherwise, returns the argument. -
checkNotNullWithIAE
Checks that the given argument is not null. If it is, throwsIllegalArgumentException. Otherwise, returns the argument.- Throws:
IllegalArgumentException
-
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, throwsIllegalArgumentException. 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:
IllegalArgumentException- if value is null.
-
checkPositive
Checks that the given argument is strictly positive. If it is not, throwsIllegalArgumentException. Otherwise, returns the argument. -
checkPositive
Checks that the given argument is strictly positive. If it is not, throwsIllegalArgumentException. Otherwise, returns the argument. -
checkPositive
Checks that the given argument is strictly positive. If it is not, throwsIllegalArgumentException. Otherwise, returns the argument. -
checkPositive
Checks that the given argument is strictly positive. If it is not, throwsIllegalArgumentException. Otherwise, returns the argument. -
checkPositive
Checks that the given argument is positive or zero. If it is not , throwsIllegalArgumentException. Otherwise, returns the argument. -
checkPositiveOrZero
Checks that the given argument is positive or zero. If it is not , throwsIllegalArgumentException. Otherwise, returns the argument. -
checkPositiveOrZero
Checks that the given argument is positive or zero. If it is not, throwsIllegalArgumentException. Otherwise, returns the argument. -
checkPositiveOrZero
Checks that the given argument is positive or zero. If it is not, throwsIllegalArgumentException. Otherwise, returns the argument. -
checkPositiveOrZero
Checks that the given argument is positive or zero. If it is not, throwsIllegalArgumentException. Otherwise, returns the argument. -
checkInRange
Checks that the given argument is in range. If it is not, throwsIllegalArgumentException. Otherwise, returns the argument. -
checkInRange
Checks that the given argument is in range. If it is not, throwsIllegalArgumentException. Otherwise, returns the argument. -
checkInRange
Checks that the given argument is in range. If it is not, throwsIllegalArgumentException. Otherwise, returns the argument. -
checkNonEmpty
Checks that the given argument is neither null nor empty. If it is, throwsNullPointerExceptionorIllegalArgumentException. Otherwise, returns the argument. -
checkNonEmpty
Checks that the given argument is neither null nor empty. If it is, throwsNullPointerExceptionorIllegalArgumentException. Otherwise, returns the argument. -
checkNonEmpty
Checks that the given argument is neither null nor empty. If it is, throwsNullPointerExceptionorIllegalArgumentException. Otherwise, returns the argument. -
checkNonEmpty
Checks that the given argument is neither null nor empty. If it is, throwsNullPointerExceptionorIllegalArgumentException. Otherwise, returns the argument. -
checkNonEmpty
Checks that the given argument is neither null nor empty. If it is, throwsNullPointerExceptionorIllegalArgumentException. Otherwise, returns the argument. -
checkNonEmpty
Checks that the given argument is neither null nor empty. If it is, throwsNullPointerExceptionorIllegalArgumentException. Otherwise, returns the argument. -
checkNonEmpty
Checks that the given argument is neither null nor empty. If it is, throwsNullPointerExceptionorIllegalArgumentException. Otherwise, returns the argument. -
checkNonEmptyAfterTrim
Trims the given argument and checks whether it is neither null nor empty. If it is, throwsNullPointerExceptionorIllegalArgumentException. Otherwise, returns the trimmed argument.- Parameters:
value- to trim and check.name- of the parameter.- Returns:
- the trimmed (not the original) value.
- Throws:
NullPointerException- if value is null.IllegalArgumentException- if the trimmed value is empty.
-
intValue
Resolves a possibly null Integer to a primitive int, using a default value.- Parameters:
wrapper- the wrapperdefaultValue- the default value- Returns:
- the primitive value
-
longValue
Resolves a possibly null Long to a primitive long, using a default value.- Parameters:
wrapper- the wrapperdefaultValue- the default value- Returns:
- the primitive value
-