public class ObjectUtils extends Object
Modifiers | Name | Description |
---|---|---|
static Map<Class<?>, Class<?>> |
PRIMITIVE_TYPE_COMPATIBLE_CLASSES |
|
static Map<String, String> |
PRIMITIVE_TYPE_COMPATIBLE_TYPES |
Type Params | Return Type | Name and description |
---|---|---|
|
public static String |
getGetterName(String propertyName) Calculate the name for a getter method to retrieve the specified property |
|
public static String |
getPropertyForGetter(String getterName) Returns a property name equivalent for the given getter name or null if it is not a getter |
|
public static String |
getPropertyForSetter(String setterName) Returns a property name equivalent for the given setter name or null if it is not a getter |
|
public static String |
getSetterName(String propertyName) Retrieves the name of a setter for the specified property name |
|
public static boolean |
isAssignableOrConvertibleFrom(Class<?> clazz, Class<?> type) Returns true if the specified clazz parameter is either the same as, or is a superclass or super interface of, the specified type parameter. |
|
public static boolean |
isGetter(String name, Class[] args) Returns true if the name of the method specified and the number of arguments make it a javabean property |
|
public static boolean |
isGetterMethod(Method method) Finds out if the given Method is a getter method. |
|
public static boolean |
isGetterMethod(Method method, boolean removeAbstractModifier) Finds out if the given Method is a getter method. |
|
public static boolean |
isGetterMethod(MethodDescriptor method) Finds out if the given MetaMethod is a getter method. |
|
public static boolean |
isInstanceMethod(Method method) Finds out if the given Method is an instance method, i.e,
it is public and non-static. |
|
public static boolean |
isInstanceMethod(Method method, boolean removeAbstractModifier) Finds out if the given Method is an instance method, i.e,
it is public and non-static. |
|
public static boolean |
isInstanceMethod(MethodDescriptor method) Finds out if the given MethodDescriptor is an instance method, i.e,
it is public and non-static. |
|
public static boolean |
isMatchBetweenPrimitiveAndWrapperTypes(Class<?> leftType, Class<?> rightType) Detect if left and right types are matching types. |
|
public static boolean |
isMatchBetweenPrimitiveAndWrapperTypes(String leftType, String rightType) Detect if left and right types are matching types. |
|
public static boolean |
isSetter(String name, Class[] args) |
|
public static boolean |
isSetterMethod(Method method) Finds out if the given Method is a setter method. |
|
public static boolean |
isSetterMethod(Method method, boolean removeAbstractModifier) Finds out if the given Method is a setter method. |
|
public static boolean |
isSetterMethod(MethodDescriptor method) Finds out if the given MethodDescriptor is a setter method. |
|
public static byte[] |
requireNonEmpty(byte[] array) Checks that the specified array is not empty, throwing a IllegalStateException if it is. |
|
public static byte[] |
requireNonEmpty(byte[] array, String message) Checks that the specified array is not empty, throwing a customized IllegalStateException if it is. |
|
public static short[] |
requireNonEmpty(short[] array) Checks that the specified array is not empty, throwing a IllegalStateException if it is. |
|
public static short[] |
requireNonEmpty(short[] array, String message) Checks that the specified array is not empty, throwing a customized IllegalStateException if it is. |
|
public static int[] |
requireNonEmpty(int[] array) Checks that the specified array is not empty, throwing a IllegalStateException if it is. |
|
public static int[] |
requireNonEmpty(int[] array, String message) Checks that the specified array is not empty, throwing a customized IllegalStateException if it is. |
|
public static long[] |
requireNonEmpty(long[] array) Checks that the specified array is not empty, throwing a IllegalStateException if it is. |
|
public static long[] |
requireNonEmpty(long[] array, String message) Checks that the specified array is not empty, throwing a customized IllegalStateException if it is. |
|
public static float[] |
requireNonEmpty(float[] array) Checks that the specified array is not empty, throwing a IllegalStateException if it is. |
|
public static float[] |
requireNonEmpty(float[] array, String message) Checks that the specified array is not empty, throwing a customized IllegalStateException if it is. |
|
public static double[] |
requireNonEmpty(double[] array) Checks that the specified array is not empty, throwing a IllegalStateException if it is. |
|
public static double[] |
requireNonEmpty(double[] array, String message) Checks that the specified array is not empty, throwing a customized IllegalStateException if it is. |
|
public static char[] |
requireNonEmpty(char[] array) Checks that the specified array is not empty, throwing a IllegalStateException if it is. |
|
public static char[] |
requireNonEmpty(char[] array, String message) Checks that the specified array is not empty, throwing a customized IllegalStateException if it is. |
|
public static boolean[] |
requireNonEmpty(boolean[] array) Checks that the specified array is not empty, throwing a IllegalStateException if it is. |
|
public static boolean[] |
requireNonEmpty(boolean[] array, String message) Checks that the specified array is not empty, throwing a customized IllegalStateException if it is. |
<E> |
public static E[] |
requireNonEmpty(E[] array) Checks that the specified array is not empty, throwing a IllegalStateException if it is. |
<E> |
public static E[] |
requireNonEmpty(E[] array, String message) Checks that the specified array is not empty, throwing a customized IllegalStateException if it is. |
|
public static Collection<?> |
requireNonEmpty(Collection<?> collection) Checks that the specified collection is not empty, throwing a IllegalStateException if it is. |
|
public static Collection<?> |
requireNonEmpty(Collection<?> collection, String message) Checks that the specified collection is not empty, throwing a customized IllegalStateException if it is. |
|
public static Map<?, ?> |
requireNonEmpty(Map<?, ?> map) Checks that the specified map is not empty, throwing a IllegalStateException if it is. |
|
public static Map<?, ?> |
requireNonEmpty(Map<?, ?> map, String message) Checks that the specified map is not empty, throwing a customized IllegalStateException if it is. |
|
public static void |
requireState(boolean condition) Checks that the specified condition is met. |
|
public static void |
requireState(boolean condition, String message) Checks that the specified condition is met and throws a customized IllegalStateException if it is. |
Calculate the name for a getter method to retrieve the specified property
propertyName
- the name of the propertyReturns a property name equivalent for the given getter name or null if it is not a getter
getterName
- The getter nameReturns a property name equivalent for the given setter name or null if it is not a getter
setterName
- The setter nameRetrieves the name of a setter for the specified property name
propertyName
- The property nameReturns true if the specified clazz parameter is either the same as, or is a superclass or super interface of, the specified type parameter. Converts primitive types to compatible class automatically.
Returns true if the name of the method specified and the number of arguments make it a javabean property
name
- True if its a Javabean propertyargs
- The arguments Finds out if the given Method
is a getter method.
// assuming getMethod() returns an appropriate Method reference isGetterMethod(getMethod("getFoo")) = true isGetterMethod(getMethod("getfoo") ) = false isGetterMethod(getMethod("mvcGroupInit")) = false isGetterMethod(getMethod("isFoo")) = true isGetterMethod(getMethod("island")) = false
method
- a Method reference Finds out if the given Method
is a getter method.
// assuming getMethod() returns an appropriate Method reference isGetterMethod(getMethod("getFoo")) = true isGetterMethod(getMethod("getfoo") ) = false isGetterMethod(getMethod("mvcGroupInit")) = false isGetterMethod(getMethod("isFoo")) = true isGetterMethod(getMethod("island")) = false
method
- a Method reference Finds out if the given MetaMethod
is a getter method.
// assuming getMethod() returns an appropriate MethodDescriptor reference isGetterMethod(getMethod("getFoo")) = true isGetterMethod(getMethod("getfoo") ) = false isGetterMethod(getMethod("mvcGroupInit")) = false isGetterMethod(getMethod("isFoo")) = true isGetterMethod(getMethod("island")) = false
method
- a MethodDescriptor reference Finds out if the given Method
is an instance method, i.e,
it is public and non-static.
method
- a Method reference Finds out if the given Method
is an instance method, i.e,
it is public and non-static.
method
- a Method reference Finds out if the given MethodDescriptor
is an instance method, i.e,
it is public and non-static.
method
- a MethodDescriptor referenceDetect if left and right types are matching types. In particular, test if one is a primitive type and the other is the corresponding Java wrapper type. Primitive and wrapper classes may be passed to either arguments.
Detect if left and right types are matching types. In particular, test if one is a primitive type and the other is the corresponding Java wrapper type. Primitive and wrapper classes may be passed to either arguments.
Finds out if the given Method
is a setter method.
// assuming getMethod() returns an appropriate Method reference isGetterMethod(getMethod("setFoo")) = true isGetterMethod(getMethod("setfoo")) = false isGetterMethod(getMethod("mvcGroupInit")) = false
method
- a Method reference Finds out if the given Method
is a setter method.
// assuming getMethod() returns an appropriate Method reference isGetterMethod(getMethod("setFoo")) = true isGetterMethod(getMethod("setfoo")) = false isGetterMethod(getMethod("mvcGroupInit")) = false
method
- a Method reference Finds out if the given MethodDescriptor
is a setter method.
// assuming getMethod() returns an appropriate MethodDescriptor reference isGetterMethod(getMethod("setFoo")) = true isGetterMethod(getMethod("setfoo")) = false isGetterMethod(getMethod("mvcGroupInit")) = false
method
- a MethodDescriptor referenceChecks that the specified array is not empty, throwing a IllegalStateException if it is.
array
is nullarray
is emptyarray
- the array to checkChecks that the specified array is not empty, throwing a customized IllegalStateException if it is.
array
is nullmessage
is blank
array
is emptyarray
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownChecks that the specified array is not empty, throwing a IllegalStateException if it is.
array
is nullarray
is emptyarray
- the array to checkChecks that the specified array is not empty, throwing a customized IllegalStateException if it is.
array
is nullmessage
is blank
array
is emptyarray
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownChecks that the specified array is not empty, throwing a IllegalStateException if it is.
array
is nullarray
is emptyarray
- the array to checkChecks that the specified array is not empty, throwing a customized IllegalStateException if it is.
array
is nullmessage
is blank
array
is emptyarray
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownChecks that the specified array is not empty, throwing a IllegalStateException if it is.
array
is nullarray
is emptyarray
- the array to checkChecks that the specified array is not empty, throwing a customized IllegalStateException if it is.
array
is nullmessage
is blank
array
is emptyarray
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownChecks that the specified array is not empty, throwing a IllegalStateException if it is.
array
is nullarray
is emptyarray
- the array to checkChecks that the specified array is not empty, throwing a customized IllegalStateException if it is.
array
is nullmessage
is blank
array
is emptyarray
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownChecks that the specified array is not empty, throwing a IllegalStateException if it is.
array
is nullarray
is emptyarray
- the array to checkChecks that the specified array is not empty, throwing a customized IllegalStateException if it is.
array
is nullmessage
is blank
array
is emptyarray
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownChecks that the specified array is not empty, throwing a IllegalStateException if it is.
array
is nullarray
is emptyarray
- the array to checkChecks that the specified array is not empty, throwing a customized IllegalStateException if it is.
array
is nullmessage
is blank
array
is emptyarray
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownChecks that the specified array is not empty, throwing a IllegalStateException if it is.
array
is nullarray
is emptyarray
- the array to checkChecks that the specified array is not empty, throwing a customized IllegalStateException if it is.
array
is nullmessage
is blank
array
is emptyarray
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownChecks that the specified array is not empty, throwing a IllegalStateException if it is.
array
is nullarray
is emptyarray
- the array to checkChecks that the specified array is not empty, throwing a customized IllegalStateException if it is.
array
is nullmessage
is blank
array
is emptyarray
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownChecks that the specified collection is not empty, throwing a IllegalStateException if it is.
collection
is nullcollection
is emptycollection
- the collection to checkChecks that the specified collection is not empty, throwing a customized IllegalStateException if it is.
collection
is nullmessage
is blank
collection
is emptycollection
- the collection to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownChecks that the specified map is not empty, throwing a IllegalStateException if it is.
map
is nullmap
is emptymap
- the map to checkChecks that the specified map is not empty, throwing a customized IllegalStateException if it is.
map
is nullmessage
is blank
map
is emptymap
- the map to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownChecks that the specified condition is met. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:
public Foo(int[] array) { GriffonClassUtils.requireState(array.length > 0); }
condition
evaluates to falsecondition
- the condition to checkChecks that the specified condition is met and throws a customized IllegalStateException if it is. This method is designed primarily for doing parameter validation in methods and constructors with multiple parameters, as demonstrated below:
public Foo(int[] array) { GriffonClassUtils.requireState(array.length > 0, "array must not be empty"); }
condition
evaluates to falsecondition
- the condition to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrown