Top Description Fields Constructors Methods
io.netty.util.internal

public final Class ObjectUtil

extends Object
Class Inheritance
Imports
java.util.Collection, .Map

A grab-bag of useful utility methods.

Field Summary

Modifier and TypeField and Description
private static final double
private static final float
private static final int
private static final long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static int
checkInRange(int i, int start, int end, String name)

Checks that the given argument is in range.

public static long
checkInRange(long l, long start, long end, String name)

Checks that the given argument is in range.

public static <T> T[]
checkNonEmpty(T[] array, String name)

Checks that the given argument is neither null nor empty.

public static byte[]
checkNonEmpty(byte[] array, String name)

Checks that the given argument is neither null nor empty.

public static char[]
checkNonEmpty(char[] array, String name)

Checks that the given argument is neither null nor empty.

public static <T extends Collection<?>> T
checkNonEmpty(T collection, String name)

Checks that the given argument is neither null nor empty.

public static String
checkNonEmpty(final String value, final String name)

Checks that the given argument is neither null nor empty.

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.

public static CharSequence
checkNonEmpty(final CharSequence value, final String name)

Checks that the given argument is neither null nor empty.

public static String

Returns:

the trimmed (not the original) value.
checkNonEmptyAfterTrim
(final String
to trim and check.
value
,
final String
of the parameter.
name
)

Trims the given argument and checks whether it is neither null nor empty.

public static <T> T
checkNotNull(T arg, String text)

Checks that the given argument is not null.

public static <
type of the given argument value.
T
>
T

Returns:

the given argument value.
checkNotNullArrayParam
(T
to check.
value
,
int
of the array, belongs to the exception message.
index
,
String
of the parameter, belongs to the exception message.
name
)

Checks that the given argument is not null.

public static <T> T
checkNotNullWithIAE(final T arg, final String paramName)

Checks that the given argument is not null.

public static int
checkPositive(int i, String name)

Checks that the given argument is strictly positive.

public static long
checkPositive(long l, String name)

Checks that the given argument is strictly positive.

public static double
checkPositive(final double d, final String name)

Checks that the given argument is strictly positive.

public static float
checkPositive(final float f, final String name)

Checks that the given argument is strictly positive.

public static int
checkPositiveOrZero(int i, String name)

Checks that the given argument is positive or zero.

public static long
checkPositiveOrZero(long l, String name)

Checks that the given argument is positive or zero.

public static double
checkPositiveOrZero(final double d, final String name)

Checks that the given argument is positive or zero.

public static float
checkPositiveOrZero(final float f, final String name)

Checks that the given argument is positive or zero.

public static <T> T[]
deepCheckNotNull(String text, T... varargs)

Check that the given varargs is not null and does not contain elements null elements.

public static int

Returns:

the primitive value
intValue
(Integer
the wrapper
wrapper
,
int
the default value
defaultValue
)

Resolves a possibly null Integer to a primitive int, using a default value.

public static long

Returns:

the primitive value
longValue
(Long
the wrapper
wrapper
,
long
the default value
defaultValue
)

Resolves a possibly null Long to a primitive long, using a default value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DOUBLE_ZEROback to summary
private static final double DOUBLE_ZERO
FLOAT_ZEROback to summary
private static final float FLOAT_ZERO
INT_ZEROback to summary
private static final int INT_ZERO
LONG_ZEROback to summary
private static final long LONG_ZERO

Constructor Detail

ObjectUtilback to summary
private ObjectUtil()

Method Detail

checkInRangeback to summary
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.

checkInRangeback to summary
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.

checkNonEmptyback to summary
public static <T> T[] checkNonEmpty(T[] array, String name)

Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.

checkNonEmptyback to summary
public static byte[] checkNonEmpty(byte[] array, String name)

Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.

checkNonEmptyback to summary
public static char[] checkNonEmpty(char[] array, String name)

Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.

checkNonEmptyback to summary
public static <T extends Collection<?>> T checkNonEmpty(T collection, String name)

Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.

checkNonEmptyback to summary
public static String checkNonEmpty(final String value, final String name)

Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.

checkNonEmptyback to summary
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.

checkNonEmptyback to summary
public static CharSequence checkNonEmpty(final CharSequence value, final String name)

Checks that the given argument is neither null nor empty. If it is, throws NullPointerException or IllegalArgumentException. Otherwise, returns the argument.

checkNonEmptyAfterTrimback to summary
public static String checkNonEmptyAfterTrim(final String value, final 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:String

to trim and check.

name:String

of the parameter.

Returns:String

the trimmed (not the original) value.

Exceptions
NullPointerException:
if value is null.
IllegalArgumentException:
if the trimmed value is empty.
checkNotNullback to summary
public static <T> T checkNotNull(T arg, String text)

Checks that the given argument is not null. If it is, throws NullPointerException. Otherwise, returns the argument.

checkNotNullArrayParamback to summary
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.

Parameters
<T>
type of the given argument value.
value:T

to check.

index:int

of the array, belongs to the exception message.

name:String

of the parameter, belongs to the exception message.

Returns:T

the given argument value.

Exceptions
IllegalArgumentException:
if value is null.
checkNotNullWithIAEback to summary
public static <T> T checkNotNullWithIAE(final T arg, final String paramName) throws IllegalArgumentException

Checks that the given argument is not null. If it is, throws IllegalArgumentException. Otherwise, returns the argument.

checkPositiveback to summary
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.

checkPositiveback to summary
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.

checkPositiveback to summary
public static double checkPositive(final double d, final String name)

Checks that the given argument is strictly positive. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.

checkPositiveback to summary
public static float checkPositive(final float f, final String name)

Checks that the given argument is strictly positive. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.

checkPositiveOrZeroback to summary
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.

checkPositiveOrZeroback to summary
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.

checkPositiveOrZeroback to summary
public static double checkPositiveOrZero(final double d, final String name)

Checks that the given argument is positive or zero. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.

checkPositiveOrZeroback to summary
public static float checkPositiveOrZero(final float f, final String name)

Checks that the given argument is positive or zero. If it is not, throws IllegalArgumentException. Otherwise, returns the argument.

deepCheckNotNullback to summary
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.

intValueback to summary
public static int intValue(Integer wrapper, int defaultValue)

Resolves a possibly null Integer to a primitive int, using a default value.

Parameters
wrapper:Integer

the wrapper

defaultValue:int

the default value

Returns:int

the primitive value

longValueback to summary
public static long longValue(Long wrapper, long defaultValue)

Resolves a possibly null Long to a primitive long, using a default value.

Parameters
wrapper:Long

the wrapper

defaultValue:long

the default value

Returns:long

the primitive value