public class GriffonClassUtils
extends java.lang.Object
Contains utility methods copied from commons-lang and commons-beanutils in order to reduce dependencies on external libraries.
Contains code copied from commons-beanutils and commons-langs
Modifier and Type | Field and Description |
---|---|
static java.lang.Object[] |
EMPTY_ARGS |
static java.lang.Class<?>[] |
EMPTY_CLASS_ARRAY |
static java.lang.Object[] |
EMPTY_OBJECT_ARRAY |
static java.lang.String |
INNER_CLASS_SEPARATOR
The inner class separator String:
"$" . |
static char |
INNER_CLASS_SEPARATOR_CHAR
The inner class separator character:
'$' == 36 . |
static java.lang.String |
PACKAGE_SEPARATOR
The package separator String:
"." . |
static char |
PACKAGE_SEPARATOR_CHAR
The package separator character:
'.' == 46 . |
static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> |
PRIMITIVE_TYPE_COMPATIBLE_CLASSES |
static java.util.Map<java.lang.String,java.lang.String> |
PRIMITIVE_TYPE_COMPATIBLE_TYPES |
Modifier and Type | Method and Description |
---|---|
static java.lang.Object[] |
collectionToObjectArray(java.util.Collection<?> c)
Convenience method for converting a collection to an Object[]
|
static java.lang.Class<?>[] |
convertToTypeArray(java.lang.Object[] args)
param instance array to the type array
|
static java.util.Collection<?> |
createConcreteCollection(java.lang.Class<?> interfaceType)
Creates a concrete collection for the supplied interface
|
static java.lang.reflect.Field[] |
getAllDeclaredFields(java.lang.Class<?> clazz)
Returns an array of
Field objects reflecting all the fields
declared by the class and its hierarchy, represented by this
Class object. |
static boolean |
getBooleanFromMap(java.lang.String key,
java.util.Map<java.lang.String,java.lang.Object> map)
Retrieves a boolean value from a Map for the given key
|
static java.lang.reflect.Field |
getField(java.lang.Class<?> clazz,
java.lang.String name)
Get the a declared field on a class
|
static java.lang.reflect.Field |
getField(java.lang.Object obj,
java.lang.String name)
Get the a declared field on an object
|
static java.lang.Object |
getFieldValue(java.lang.Object obj,
java.lang.String name)
Get the value of a declared field on an object
|
static java.lang.String |
getGetterName(java.lang.String propertyName)
Calculate the name for a getter method to retrieve the specified property
|
static java.lang.String |
getPackageName(java.lang.Class<?> cls)
Gets the package name of a
Class . |
static java.lang.String |
getPackageName(java.lang.Object object,
java.lang.String valueIfNull)
Gets the package name of an
Object . |
static java.lang.String |
getPackageName(java.lang.String className)
Gets the package name from a
String . |
static java.beans.PropertyDescriptor[] |
getPropertiesAssignableToType(java.lang.Class<?> clazz,
java.lang.Class<?> propertySuperType)
Retrieves all the properties of the given class which are assignable to the given type
|
static java.beans.PropertyDescriptor[] |
getPropertiesOfType(java.lang.Class<?> clazz,
java.lang.Class<?> propertyType)
Retrieves all the properties of the given class for the given type
|
static java.beans.PropertyDescriptor |
getProperty(java.lang.Class<?> clazz,
java.lang.String propertyName,
java.lang.Class<?> propertyType)
Retrieves a property of the given class of the specified name and type
|
static java.lang.Object |
getProperty(java.lang.Object bean,
java.lang.String name)
Return the value of the specified property of the specified bean,
no matter which property reference format is used, with no
type conversions.
|
static java.beans.PropertyDescriptor |
getPropertyDescriptor(java.lang.Class<?> clazz,
java.lang.String name)
Retrieve the property descriptor for the specified property of the
specified class, or return
null if there is no such
descriptor. |
static java.beans.PropertyDescriptor |
getPropertyDescriptor(java.lang.Object bean,
java.lang.String name)
Retrieve the property descriptor for the specified property of the
specified bean, or return
null if there is no such
descriptor. |
static java.beans.PropertyDescriptor |
getPropertyDescriptorForValue(java.lang.Object instance,
java.lang.Object propertyValue)
Retrieves a PropertyDescriptor for the specified instance and property value
|
static java.beans.PropertyDescriptor[] |
getPropertyDescriptors(java.lang.Class<?> beanClass)
Retrieve the property descriptors for the specified class,
introspecting and caching them the first time a particular bean class
is encountered.
|
static java.lang.String |
getPropertyForGetter(java.lang.String getterName)
Returns a property name equivalent for the given getter name or null if it is not a getter
|
static java.lang.String |
getPropertyForSetter(java.lang.String setterName)
Returns a property name equivalent for the given setter name or null if it is not a getter
|
static java.lang.Object |
getPropertyOrStaticPropertyOrFieldValue(java.lang.Object obj,
java.lang.String name)
Looks for a property of the reference instance with a given name.
|
static java.lang.Class<?> |
getPropertyType(java.lang.Class<?> clazz,
java.lang.String propertyName)
Returns the type of the given property contained within the specified class
|
static java.lang.Object |
getPropertyValue(java.lang.Object bean,
java.lang.String name)
Returns the value of a property.
|
static java.lang.Object |
getPropertyValueOfNewInstance(java.lang.Class<?> clazz,
java.lang.String propertyName)
Returns the value of the specified property and type from an instance of the specified Griffon class
|
static java.lang.Object |
getPropertyValueOfNewInstance(java.lang.Class<?> clazz,
java.lang.String propertyName,
java.lang.Class<?> propertyType)
Returns the value of the specified property and type from an instance of the specified Griffon class
|
static java.lang.reflect.Method |
getReadMethod(java.lang.Class<?> clazz,
java.beans.PropertyDescriptor descriptor)
Return an accessible property getter method for this property,
if there is one; otherwise return
null . |
static java.lang.reflect.Method |
getReadMethod(java.beans.PropertyDescriptor descriptor)
Return an accessible property getter method for this property,
if there is one; otherwise return
null . |
static java.lang.String |
getSetterName(java.lang.String propertyName)
Retrieves the name of a setter for the specified property name
|
static java.lang.String |
getShortClassName(java.lang.Class<?> cls)
Gets the class name minus the package name from a
Class . |
static java.lang.String |
getShortClassName(java.lang.Object object,
java.lang.String valueIfNull)
Gets the class name minus the package name for an
Object . |
static java.lang.String |
getShortClassName(java.lang.String className)
Gets the class name minus the package name from a String.
|
static java.lang.Object |
getStaticPropertyValue(java.lang.Class<?> clazz,
java.lang.String name)
Get a static property value, which has a public static getter or is just a public static field.
|
static java.lang.reflect.Method |
getWriteMethod(java.lang.Class<?> clazz,
java.beans.PropertyDescriptor descriptor)
Return an accessible property setter method for this property,
if there is one; otherwise return
null . |
static java.lang.reflect.Method |
getWriteMethod(java.beans.PropertyDescriptor descriptor)
Return an accessible property setter method for this property,
if there is one; otherwise return
null . |
static boolean |
hasMethodAnnotatedwith(java.lang.Object instance,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation) |
static java.lang.Object |
instantiate(java.lang.Class<?> clazz,
java.lang.Object[] args) |
static java.lang.Object |
instantiateClass(java.lang.Class<?> clazz)
Instantiates a Class, wrapping any exceptions in a RuntimeException.
|
static void |
invokeAnnotatedMethod(java.lang.Object instance,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation) |
static java.lang.Object |
invokeExactInstanceMethod(java.lang.Object object,
java.lang.String methodName) |
static java.lang.Object |
invokeExactInstanceMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... args) |
static java.lang.Object |
invokeExactInstanceMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object arg) |
static java.lang.Object |
invokeExactStaticMethod(java.lang.Class<?> type,
java.lang.String methodName) |
static java.lang.Object |
invokeExactStaticMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Object... args) |
static java.lang.Object |
invokeExactStaticMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Object arg) |
static java.lang.Object |
invokeInstanceMethod(java.lang.Object object,
java.lang.String methodName) |
static java.lang.Object |
invokeInstanceMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object... args) |
static java.lang.Object |
invokeInstanceMethod(java.lang.Object object,
java.lang.String methodName,
java.lang.Object arg) |
static java.lang.Object |
invokeStaticMethod(java.lang.Class<?> type,
java.lang.String methodName) |
static java.lang.Object |
invokeStaticMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Object... args) |
static java.lang.Object |
invokeStaticMethod(java.lang.Class<?> type,
java.lang.String methodName,
java.lang.Object arg) |
static boolean |
isArtifactMethod(java.lang.reflect.Method method)
Finds out if the given
Method belongs to the set of
predefined Artifact methods by convention. |
static boolean |
isArtifactMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method belongs to the set of
predefined Artifact methods by convention. |
static boolean |
isArtifactMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor belongs to the set of
predefined Artifact methods by convention. |
static boolean |
isAssignableOrConvertibleFrom(java.lang.Class<?> clazz,
java.lang.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.
|
static boolean |
isBasicMethod(java.lang.reflect.Method method)
Finds out if the given
Method belongs either to the
Object class or the GroovyObject class. |
static boolean |
isBasicMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method belongs either to the
Object class or the GroovyObject class. |
static boolean |
isBasicMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor belongs either to the
Object class or the GroovyObject class. |
static boolean |
isClassBelowPackage(java.lang.Class<?> clazz,
java.util.List<?> packageList)
Returns whether the specified class is either within one of the specified packages or
within a subpackage of one of the packages
|
static boolean |
isContributionMethod(java.lang.reflect.Method method)
Finds out if the given Method represents a contribution method
by matching its name against the following pattern:
"^with[A-Z][a-z0-9_]*[\w]*$"
|
static boolean |
isContributionMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given Method represents a contribution method
by matching its name against the following pattern:
"^with[A-Z][a-z0-9_]*[\w]*$"
|
static boolean |
isContributionMethod(MethodDescriptor method)
Finds out if the given Method represents a contribution method
by matching its name against the following pattern:
"^with[A-Z][a-z0-9_]*[\w]*$"
|
static boolean |
isContributionMethod(java.lang.String name)
Finds out if the given string represents the name of a
contribution method by matching against the following pattern:
"^with[A-Z][a-z0-9_]*[\w]*$"
|
static boolean |
isEventHandler(java.lang.reflect.Method method)
Finds out if the given Method represents an event handler
by matching its name against the following pattern:
"^on[A-Z][\\w]*$"
|
static boolean |
isEventHandler(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given Method represents an event handler
by matching its name against the following pattern:
"^on[A-Z][\\w]*$"
|
static boolean |
isEventHandler(MethodDescriptor method)
Finds out if the given Method represents an event handler
by matching its name against the following pattern:
"^on[A-Z][\\w]*$"
|
static boolean |
isEventHandler(java.lang.String name)
Finds out if the given string represents the name of an
event handler by matching against the following pattern:
"^on[A-Z][\\w]*$"
|
static boolean |
isEventPublisherMethod(java.lang.reflect.Method method)
Finds out if the given
Method belongs to the set of
predefined event publisher methods by convention. |
static boolean |
isEventPublisherMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method belongs to the set of
predefined event publisher methods by convention. |
static boolean |
isEventPublisherMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor belongs to the set of
predefined event publisher methods by convention. |
static boolean |
isGetter(java.lang.String name,
java.lang.Class[] args)
Returns true if the name of the method specified and the number of arguments make it a javabean property
|
static boolean |
isGetterMethod(java.lang.reflect.Method method)
Finds out if the given
Method is a getter method. |
static boolean |
isGetterMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method is a getter method. |
static boolean |
isGetterMethod(MethodDescriptor method)
Finds out if the given
MetaMethod is a getter method. |
static boolean |
isGroovyInjectedMethod(java.lang.reflect.Method method)
Finds out if the given
Method was injected by the Groovy
compiler. |
static boolean |
isGroovyInjectedMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method was injected by the Groovy
compiler. |
static boolean |
isGroovyInjectedMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor was injected by the Groovy
compiler. |
static boolean |
isInstanceMethod(java.lang.reflect.Method method)
Finds out if the given
Method is an instance method, i.e,
it is public and non-static. |
static boolean |
isInstanceMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method is an instance method, i.e,
it is public and non-static. |
static boolean |
isInstanceMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor is an instance method, i.e,
it is public and non-static. |
static boolean |
isMatchBetweenPrimitiveAndWrapperTypes(java.lang.Class<?> leftType,
java.lang.Class<?> rightType)
Detect if left and right types are matching types.
|
static boolean |
isMatchBetweenPrimitiveAndWrapperTypes(java.lang.String leftType,
java.lang.String rightType)
Detect if left and right types are matching types.
|
static boolean |
isMessageSourceMethod(java.lang.reflect.Method method)
Finds out if the given
Method belongs to the set of
predefined message source methods by convention. |
static boolean |
isMessageSourceMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method belongs to the set of
predefined message source methods by convention. |
static boolean |
isMessageSourceMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor belongs to the set of
predefined message source methods by convention. |
static boolean |
isMvcMethod(java.lang.reflect.Method method)
Finds out if the given
Method belongs to the set of
predefined MVC methods by convention. |
static boolean |
isMvcMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method belongs to the set of
predefined MVC methods by convention. |
static boolean |
isMvcMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor belongs to the set of
predefined MVC methods by convention. |
static boolean |
isObservableMethod(java.lang.reflect.Method method)
Finds out if the given
Method belongs to the set of
predefined observable methods by convention. |
static boolean |
isObservableMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method belongs to the set of
predefined observable methods by convention. |
static boolean |
isObservableMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor belongs to the set of
predefined observable methods by convention. |
static boolean |
isPlainMethod(java.lang.reflect.Method method)
Finds out if the given
Method matches the following criteria:
isInstanceMethod(method)
! isBasicMethod(method)
! isGroovyInjectedMethod(method)
! isThreadingMethod(method)
! isArtifactMethod(method)
! isMvcMethod(method)
! isServiceMethod(method)
! isEventPublisherMethod(method)
! isObservableMethod(method)
! isResourceHandlerMethod(method)
! isGetterMethod(method)
! isSetterMethod(method)
! isContributionMethod(method)
|
static boolean |
isPlainMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method matches the following criteria:
isInstanceMethod(method)
! isBasicMethod(method)
! isGroovyInjectedMethod(method)
! isThreadingMethod(method)
! isArtifactMethod(method)
! isMvcMethod(method)
! isServiceMethod(method)
! isEventPublisherMethod(method)
! isObservableMethod(method)
! isResourceHandlerMethod(method)
! isGetterMethod(method)
! isSetterMethod(method)
! isContributionMethod(method)
|
static boolean |
isPlainMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor matches the following criteria:
isInstanceMethod(method)
! isBasicMethod(method)
! isGroovyInjectedMethod(method)
! isThreadingMethod(method)
! isArtifactMethod(method)
! isMvcMethod(method)
! isServiceMethod(method)
! isEventPublisherMethod(method)
! isObservableMethod(method)
! isResourceHandlerMethod(method)
! isGetterMethod(method)
! isSetterMethod(method)
! isContributionMethod(method)
|
static boolean |
isPropertyInherited(java.lang.Class<?> clz,
java.lang.String propertyName)
Checks whether the specified property is inherited from a super class
|
static boolean |
isPropertyOfType(java.lang.Class<?> clazz,
java.lang.String propertyName,
java.lang.Class<?> type)
Returns true if the specified property in the specified class is of the specified type
|
static boolean |
isPublicField(java.lang.Object obj,
java.lang.String name)
Work out if the specified object has a public field with the name supplied.
|
static boolean |
isPublicStatic(java.lang.reflect.Field f)
Determine whether the field is declared public static
|
static boolean |
isPublicStatic(java.lang.reflect.Method m)
Determine whether the method is declared public static
|
static boolean |
isReadable(java.lang.Object bean,
java.lang.String name)
Return
true if the specified property name identifies
a readable property on the specified bean; otherwise, return
false . |
static boolean |
isResourceHandlerMethod(java.lang.reflect.Method method)
Finds out if the given
Method belongs to the set of
predefined resources methods by convention. |
static boolean |
isResourceHandlerMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method belongs to the set of
predefined resources methods by convention. |
static boolean |
isResourceHandlerMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor belongs to the set of
predefined resources methods by convention. |
static boolean |
isResourceResolverMethod(java.lang.reflect.Method method)
Finds out if the given
Method belongs to the set of
predefined resource resolver methods by convention. |
static boolean |
isResourceResolverMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method belongs to the set of
predefined resource resolver methods by convention. |
static boolean |
isResourceResolverMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor belongs to the set of
predefined resource resolver methods by convention. |
static boolean |
isSetter(java.lang.String name,
java.lang.Class[] args) |
static boolean |
isSetterMethod(java.lang.reflect.Method method)
Finds out if the given
Method is a setter method. |
static boolean |
isSetterMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method is a setter method. |
static boolean |
isSetterMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor is a setter method. |
static boolean |
isStaticProperty(java.lang.Class<?> clazz,
java.lang.String propertyName)
Work out if the specified property is readable and static.
|
static boolean |
isThreadingMethod(java.lang.reflect.Method method)
Finds out if the given
Method belongs to the set of
predefined threading methods by convention. |
static boolean |
isThreadingMethod(java.lang.reflect.Method method,
boolean removeAbstractModifier)
Finds out if the given
Method belongs to the set of
predefined threading methods by convention. |
static boolean |
isThreadingMethod(MethodDescriptor method)
Finds out if the given
MethodDescriptor belongs to the set of
predefined threading methods by convention. |
static void |
isTrue(boolean expression,
java.lang.String message)
Validate that the argument condition is
true ; otherwise
throwing an exception with the specified message. |
static boolean |
isWritable(java.lang.Object bean,
java.lang.String name)
Return
true if the specified property name identifies
a writable property on the specified bean; otherwise, return
false . |
static boolean[] |
requireNonEmpty(boolean[] array)
Checks that the specified array is not empty, throwing a
IllegalStateException if it is. |
static boolean[] |
requireNonEmpty(boolean[] array,
java.lang.String message)
Checks that the specified array is not empty, throwing a customized
IllegalStateException if it is. |
static byte[] |
requireNonEmpty(byte[] array)
Checks that the specified array is not empty, throwing a
IllegalStateException if it is. |
static byte[] |
requireNonEmpty(byte[] array,
java.lang.String message)
Checks that the specified array is not empty, throwing a customized
IllegalStateException if it is. |
static char[] |
requireNonEmpty(char[] array)
Checks that the specified array is not empty, throwing a
IllegalStateException if it is. |
static char[] |
requireNonEmpty(char[] array,
java.lang.String message)
Checks that the specified array is not empty, throwing a customized
IllegalStateException if it is. |
static java.util.Collection<?> |
requireNonEmpty(java.util.Collection<?> collection)
Checks that the specified collection is not empty, throwing a
IllegalStateException if it is. |
static java.util.Collection<?> |
requireNonEmpty(java.util.Collection<?> collection,
java.lang.String message)
Checks that the specified collection is not empty, throwing a customized
IllegalStateException if it is. |
static double[] |
requireNonEmpty(double[] array)
Checks that the specified array is not empty, throwing a
IllegalStateException if it is. |
static double[] |
requireNonEmpty(double[] array,
java.lang.String message)
Checks that the specified array is not empty, throwing a customized
IllegalStateException if it is. |
static <E> E[] |
requireNonEmpty(E[] array)
Checks that the specified array is not empty, throwing a
IllegalStateException if it is. |
static <E> E[] |
requireNonEmpty(E[] array,
java.lang.String message)
Checks that the specified array is not empty, throwing a customized
IllegalStateException if it is. |
static float[] |
requireNonEmpty(float[] array)
Checks that the specified array is not empty, throwing a
IllegalStateException if it is. |
static float[] |
requireNonEmpty(float[] array,
java.lang.String message)
Checks that the specified array is not empty, throwing a customized
IllegalStateException if it is. |
static int[] |
requireNonEmpty(int[] array)
Checks that the specified array is not empty, throwing a
IllegalStateException if it is. |
static int[] |
requireNonEmpty(int[] array,
java.lang.String message)
Checks that the specified array is not empty, throwing a customized
IllegalStateException if it is. |
static long[] |
requireNonEmpty(long[] array)
Checks that the specified array is not empty, throwing a
IllegalStateException if it is. |
static long[] |
requireNonEmpty(long[] array,
java.lang.String message)
Checks that the specified array is not empty, throwing a customized
IllegalStateException if it is. |
static java.util.Map<?,?> |
requireNonEmpty(java.util.Map<?,?> map)
Checks that the specified map is not empty, throwing a
IllegalStateException if it is. |
static java.util.Map<?,?> |
requireNonEmpty(java.util.Map<?,?> map,
java.lang.String message)
Checks that the specified map is not empty, throwing a customized
IllegalStateException if it is. |
static short[] |
requireNonEmpty(short[] array)
Checks that the specified array is not empty, throwing a
IllegalStateException if it is. |
static short[] |
requireNonEmpty(short[] array,
java.lang.String message)
Checks that the specified array is not empty, throwing a customized
IllegalStateException if it is. |
static void |
requireState(boolean condition)
Checks that the specified condition is met.
|
static void |
requireState(boolean condition,
java.lang.String message)
Checks that the specified condition is met and throws a customized
IllegalStateException if it is. |
static void |
setField(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
Sets the value of the specified field of the specified bean.
|
static void |
setFieldOrPropertyValue(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
Sets or updates an object's property.
|
static void |
setFields(java.lang.Object bean,
java.util.Map<java.lang.String,java.lang.Object> fields)
Sets or updates field values on an object.
|
static void |
setFieldsNoException(java.lang.Object bean,
java.util.Map<java.lang.String,java.lang.Object> fields)
Sets or updates field values on an object.
|
static void |
setFieldsOrProperties(java.lang.Object bean,
java.util.Map<java.lang.String,java.lang.Object> properties)
Sets or updates an object's properties.
|
static void |
setFieldsOrPropertiesNoException(java.lang.Object bean,
java.util.Map<java.lang.String,java.lang.Object> properties)
Sets or updates an object's properties.
|
static void |
setFieldValue(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
Sets or updates an object's field.
|
static void |
setFieldValueNoException(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
Sets or updates an object's field.
|
static void |
setProperties(java.lang.Object bean,
java.util.Map<java.lang.String,java.lang.Object> properties)
Sets or updates properties on an object.
|
static void |
setPropertiesNoException(java.lang.Object bean,
java.util.Map<java.lang.String,java.lang.Object> properties)
Sets or updates properties on an object.
|
static void |
setPropertiesOrFields(java.lang.Object bean,
java.util.Map<java.lang.String,java.lang.Object> properties)
Sets or updates an object's properties.
|
static void |
setPropertiesOrFieldsNoException(java.lang.Object bean,
java.util.Map<java.lang.String,java.lang.Object> properties)
Sets or updates an object's properties.
|
static void |
setProperty(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
Sets the value of the specified property of the specified bean.
|
static void |
setPropertyOrFieldValue(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
Sets or updates an object's property.
|
static void |
setPropertyOrFieldValueNoException(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
Sets or updates an object's property.
|
static void |
setPropertyValue(java.lang.Object bean,
java.lang.String name,
java.lang.Object value)
/**
Sets or updates a property on an object.
|
public static final java.lang.Class<?>[] EMPTY_CLASS_ARRAY
public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
public static final java.lang.Object[] EMPTY_ARGS
public static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> PRIMITIVE_TYPE_COMPATIBLE_CLASSES
public static final java.util.Map<java.lang.String,java.lang.String> PRIMITIVE_TYPE_COMPATIBLE_TYPES
public static final char PACKAGE_SEPARATOR_CHAR
The package separator character: '.' == 46
.
public static final java.lang.String PACKAGE_SEPARATOR
The package separator String: "."
.
public static final char INNER_CLASS_SEPARATOR_CHAR
The inner class separator character: '$' == 36
.
public static final java.lang.String INNER_CLASS_SEPARATOR
The inner class separator String: "$"
.
public static void requireState(boolean condition)
public Foo(int[] array) { GriffonClassUtils.requireState(array.length > 0); }
condition
- the condition to checkjava.lang.IllegalStateException
- if condition
evaluates to falsepublic static void requireState(boolean condition, java.lang.String message)
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
- the condition to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.IllegalStateException
- if condition
evaluates to falsepublic static byte[] requireNonEmpty(@Nonnull byte[] array)
IllegalStateException
if it is.array
- the array to checkjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalStateException
- if array
is emptypublic static byte[] requireNonEmpty(@Nonnull byte[] array, @Nonnull java.lang.String message)
IllegalStateException
if it is.array
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalArgumentException
- if message
is blank
java.lang.IllegalStateException
- if array
is emptypublic static short[] requireNonEmpty(@Nonnull short[] array)
IllegalStateException
if it is.array
- the array to checkjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalStateException
- if array
is emptypublic static short[] requireNonEmpty(@Nonnull short[] array, @Nonnull java.lang.String message)
IllegalStateException
if it is.array
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalArgumentException
- if message
is blank
java.lang.IllegalStateException
- if array
is emptypublic static int[] requireNonEmpty(@Nonnull int[] array)
IllegalStateException
if it is.array
- the array to checkjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalStateException
- if array
is emptypublic static int[] requireNonEmpty(@Nonnull int[] array, @Nonnull java.lang.String message)
IllegalStateException
if it is.array
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalArgumentException
- if message
is blank
java.lang.IllegalStateException
- if array
is emptypublic static long[] requireNonEmpty(@Nonnull long[] array)
IllegalStateException
if it is.array
- the array to checkjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalStateException
- if array
is emptypublic static long[] requireNonEmpty(@Nonnull long[] array, @Nonnull java.lang.String message)
IllegalStateException
if it is.array
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalArgumentException
- if message
is blank
java.lang.IllegalStateException
- if array
is emptypublic static float[] requireNonEmpty(@Nonnull float[] array)
IllegalStateException
if it is.array
- the array to checkjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalStateException
- if array
is emptypublic static float[] requireNonEmpty(@Nonnull float[] array, @Nonnull java.lang.String message)
IllegalStateException
if it is.array
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalArgumentException
- if message
is blank
java.lang.IllegalStateException
- if array
is emptypublic static double[] requireNonEmpty(@Nonnull double[] array)
IllegalStateException
if it is.array
- the array to checkjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalStateException
- if array
is emptypublic static double[] requireNonEmpty(@Nonnull double[] array, @Nonnull java.lang.String message)
IllegalStateException
if it is.array
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalArgumentException
- if message
is blank
java.lang.IllegalStateException
- if array
is emptypublic static char[] requireNonEmpty(@Nonnull char[] array)
IllegalStateException
if it is.array
- the array to checkjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalStateException
- if array
is emptypublic static char[] requireNonEmpty(@Nonnull char[] array, @Nonnull java.lang.String message)
IllegalStateException
if it is.array
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalArgumentException
- if message
is blank
java.lang.IllegalStateException
- if array
is emptypublic static boolean[] requireNonEmpty(@Nonnull boolean[] array)
IllegalStateException
if it is.array
- the array to checkjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalStateException
- if array
is emptypublic static boolean[] requireNonEmpty(@Nonnull boolean[] array, @Nonnull java.lang.String message)
IllegalStateException
if it is.array
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalArgumentException
- if message
is blank
java.lang.IllegalStateException
- if array
is emptypublic static <E> E[] requireNonEmpty(@Nonnull E[] array)
IllegalStateException
if it is.array
- the array to checkjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalStateException
- if array
is emptypublic static <E> E[] requireNonEmpty(@Nonnull E[] array, @Nonnull java.lang.String message)
IllegalStateException
if it is.array
- the array to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.NullPointerException
- if array
is nulljava.lang.IllegalArgumentException
- if message
is blank
java.lang.IllegalStateException
- if array
is emptypublic static java.util.Collection<?> requireNonEmpty(@Nonnull java.util.Collection<?> collection)
IllegalStateException
if it is.collection
- the collection to checkjava.lang.NullPointerException
- if collection
is nulljava.lang.IllegalStateException
- if collection
is emptypublic static java.util.Collection<?> requireNonEmpty(@Nonnull java.util.Collection<?> collection, @Nonnull java.lang.String message)
IllegalStateException
if it is.collection
- the collection to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.NullPointerException
- if collection
is nulljava.lang.IllegalArgumentException
- if message
is blank
java.lang.IllegalStateException
- if collection
is emptypublic static java.util.Map<?,?> requireNonEmpty(@Nonnull java.util.Map<?,?> map)
IllegalStateException
if it is.map
- the map to checkjava.lang.NullPointerException
- if map
is nulljava.lang.IllegalStateException
- if map
is emptypublic static java.util.Map<?,?> requireNonEmpty(@Nonnull java.util.Map<?,?> map, @Nonnull java.lang.String message)
IllegalStateException
if it is.map
- the map to checkmessage
- detail message to be used in the event that a IllegalStateException
is thrownjava.lang.NullPointerException
- if map
is nulljava.lang.IllegalArgumentException
- if message
is blank
java.lang.IllegalStateException
- if map
is emptypublic static boolean isEventHandler(@Nonnull java.lang.String name)
isEventHandler("onBootstrapEnd") = true isEventHandler("mvcGroupInit") = false isEventHandler("online") = false
name
- the name of a possible event handlerpublic static boolean isEventHandler(@Nonnull java.lang.reflect.Method method)
// assuming getMethod() returns an appropriate Method reference isEventHandler(getMethod("onBootstrapEnd")) = true isEventHandler(getMethod("mvcGroupInit")) = false isEventHandler(getMethod("online")) = false
method
- a Method referencepublic static boolean isEventHandler(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
// assuming getMethod() returns an appropriate Method reference isEventHandler(getMethod("onBootstrapEnd")) = true isEventHandler(getMethod("mvcGroupInit")) = false isEventHandler(getMethod("online")) = false
method
- a Method referencepublic static boolean isEventHandler(@Nonnull MethodDescriptor method)
// assuming getMethod() returns an appropriate MethodDescriptor reference isEventHandler(getMethod("onBootstrapEnd")) = true isEventHandler(getMethod("mvcGroupInit")) = false isEventHandler(getMethod("online")) = false
method
- a MethodDescriptor referencepublic static boolean isBasicMethod(@Nonnull java.lang.reflect.Method method)
Method
belongs either to the
Object
class or the GroovyObject
class.method
- a Method referenceObject
or
GroovyObject
, false otherwise.public static boolean isBasicMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
belongs either to the
Object
class or the GroovyObject
class.method
- a Method referenceObject
or
GroovyObject
, false otherwise.public static boolean isBasicMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
belongs either to the
Object
class or the GroovyObject
class.method
- a MethodDescriptor referenceObject
or
GroovyObject
, false otherwise.public static boolean isContributionMethod(@Nonnull java.lang.String name)
isContributionMethod("withRest") = true isContributionMethod("withMVCGroup") = false isContributionMethod("without") = false
name
- the name of a possible contribution methodpublic static boolean isContributionMethod(@Nonnull java.lang.reflect.Method method)
// assuming getMethod() returns an appropriate Method reference isContributionMethod(getMethod("withRest")) = true isContributionMethod(getMethod("withMVCGroup")) = false isContributionMethod(getMethod("without")) = false
method
- a Method referencepublic static boolean isContributionMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
// assuming getMethod() returns an appropriate Method reference isContributionMethod(getMethod("withRest")) = true isContributionMethod(getMethod("withMVCGroup")) = false isContributionMethod(getMethod("without")) = false
method
- a Method referencepublic static boolean isContributionMethod(@Nonnull MethodDescriptor method)
// assuming getMethod() returns an appropriate MethodDescriptor reference isContributionMethod(getMethod("withRest")) = true isContributionMethod(getMethod("withMVCGroup")) = false isContributionMethod(getMethod("without")) = false
method
- a MethodDescriptor referencepublic static boolean isGroovyInjectedMethod(@Nonnull java.lang.reflect.Method method)
Method
was injected by the Groovy
compiler.Performs a basic checks against the method's name, returning true if the name starts with either "super$" or "this$".
method
- a Method referencepublic static boolean isGroovyInjectedMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
was injected by the Groovy
compiler.Performs a basic checks against the method's name, returning true if the name starts with either "super$" or "this$".
method
- a Method referencepublic static boolean isGroovyInjectedMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
was injected by the Groovy
compiler.Performs a basic checks against the method's name, returning true if the name starts with either "super$" or "this$".
method
- a MethodDescriptor referencepublic static boolean isGetterMethod(@Nonnull java.lang.reflect.Method method)
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 referencepublic static boolean isGetterMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
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 referencepublic static boolean isGetterMethod(@Nonnull MethodDescriptor method)
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 referencepublic static boolean isSetterMethod(@Nonnull java.lang.reflect.Method method)
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 referencepublic static boolean isSetterMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
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 referencepublic static boolean isSetterMethod(@Nonnull MethodDescriptor method)
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 referencepublic static boolean isArtifactMethod(@Nonnull java.lang.reflect.Method method)
Method
belongs to the set of
predefined Artifact methods by convention.
// assuming getMethod() returns an appropriate Method reference isArtifactMethod(getMethod("newInstance")) = true isArtifactMethod(getMethod("griffonDestroy")) = false isArtifactMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isArtifactMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
belongs to the set of
predefined Artifact methods by convention.
// assuming getMethod() returns an appropriate Method reference isArtifactMethod(getMethod("newInstance")) = true isArtifactMethod(getMethod("griffonDestroy")) = false isArtifactMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isArtifactMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
belongs to the set of
predefined Artifact methods by convention.
// assuming getMethod() returns an appropriate MethodDescriptor reference isArtifactMethod(getMethod("newInstance")) = true isArtifactMethod(getMethod("griffonDestroy")) = false isArtifactMethod(getMethod("foo")) = false
method
- a MethodDescriptor referencepublic static boolean isMvcMethod(@Nonnull java.lang.reflect.Method method)
Method
belongs to the set of
predefined MVC methods by convention.
// assuming getMethod() returns an appropriate Method reference isMvcMethod(getMethod("mvcGroupInit")) = true isMvcMethod(getMethod("mvcGroupDestroy")) = true isMvcMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isMvcMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
belongs to the set of
predefined MVC methods by convention.
// assuming getMethod() returns an appropriate Method reference isMvcMethod(getMethod("mvcGroupInit")) = true isMvcMethod(getMethod("mvcGroupDestroy")) = true isMvcMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isMvcMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
belongs to the set of
predefined MVC methods by convention.
// assuming getMethod() returns an appropriate MethodDescriptor reference isMvcMethod(getMethod("mvcGroupInit")) = true isMvcMethod(getMethod("mvcGroupDestroy")) = true isMvcMethod(getMethod("foo")) = false
method
- a MethodDescriptor referencepublic static boolean isThreadingMethod(@Nonnull java.lang.reflect.Method method)
Method
belongs to the set of
predefined threading methods by convention.
// assuming getMethod() returns an appropriate Method reference isThreadingMethod(getMethod("execOutsideUI")) = true isThreadingMethod(getMethod("doLater")) = true isThreadingMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isThreadingMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
belongs to the set of
predefined threading methods by convention.
// assuming getMethod() returns an appropriate Method reference isThreadingMethod(getMethod("execOutsideUI")) = true isThreadingMethod(getMethod("doLater")) = true isThreadingMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isThreadingMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
belongs to the set of
predefined threading methods by convention.
// assuming getMethod() returns an appropriate MethodDescriptor reference isThreadingMethod(getMethod("execOutsideUI")) = true isThreadingMethod(getMethod("doLater")) = true isThreadingMethod(getMethod("foo")) = false
method
- a MethodDescriptor referencepublic static boolean isEventPublisherMethod(@Nonnull java.lang.reflect.Method method)
Method
belongs to the set of
predefined event publisher methods by convention.
// assuming getMethod() returns an appropriate Method reference isEventPublisherMethod(getMethod("addEventPublisher")) = true isEventPublisherMethod(getMethod("publishEvent")) = true isEventPublisherMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isEventPublisherMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
belongs to the set of
predefined event publisher methods by convention.
// assuming getMethod() returns an appropriate Method reference isEventPublisherMethod(getMethod("addEventPublisher")) = true isEventPublisherMethod(getMethod("publishEvent")) = true isEventPublisherMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isEventPublisherMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
belongs to the set of
predefined event publisher methods by convention.
// assuming getMethod() returns an appropriate MethodDescriptor reference isEventPublisherMethod(getMethod("addEventPublisher")) = true isEventPublisherMethod(getMethod("publishEvent")) = true isEventPublisherMethod(getMethod("foo")) = false
method
- a MethodDescriptor referencepublic static boolean isObservableMethod(@Nonnull java.lang.reflect.Method method)
Method
belongs to the set of
predefined observable methods by convention.
// assuming getMethod() returns an appropriate Method reference isObservableMethod(getMethod("addPropertyChangeListener")) = true isObservableMethod(getMethod("getPropertyChangeListeners")) = true isObservableMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isObservableMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
belongs to the set of
predefined observable methods by convention.
// assuming getMethod() returns an appropriate Method reference isObservableMethod(getMethod("addPropertyChangeListener")) = true isObservableMethod(getMethod("getPropertyChangeListeners")) = true isObservableMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isObservableMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
belongs to the set of
predefined observable methods by convention.
// assuming getMethod() returns an appropriate MethodDescriptor reference isObservableMethod(getMethod("addPropertyChangeListener")) = true isObservableMethod(getMethod("getPropertyChangeListeners")) = true isObservableMethod(getMethod("foo")) = false
method
- a MethodDescriptor referencepublic static boolean isResourceHandlerMethod(@Nonnull java.lang.reflect.Method method)
Method
belongs to the set of
predefined resources methods by convention.
// assuming getMethod() returns an appropriate Method reference isResourceHandlerMethod(getMethod("getResourceAsURL")) = true isResourceHandlerMethod(getMethod("getResourceAsStream")) = true isResourceHandlerMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isResourceHandlerMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
belongs to the set of
predefined resources methods by convention.
// assuming getMethod() returns an appropriate Method reference isResourceHandlerMethod(getMethod("getResourceAsURL")) = true isResourceHandlerMethod(getMethod("getResourceAsStream")) = true isResourceHandlerMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isResourceHandlerMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
belongs to the set of
predefined resources methods by convention.
// assuming getMethod() returns an appropriate MethodDescriptor reference isResourceHandlerMethod(getMethod("getResourceAsURL")) = true isResourceHandlerMethod(getMethod("getResourceAsStream")) = true isResourceHandlerMethod(getMethod("foo")) = false
method
- a MethodDescriptor referencepublic static boolean isMessageSourceMethod(@Nonnull java.lang.reflect.Method method)
Method
belongs to the set of
predefined message source methods by convention.
// assuming getMethod() returns an appropriate Method reference isMessageSourceMethod(getMethod("getMessage")) = true isMessageSourceMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isMessageSourceMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
belongs to the set of
predefined message source methods by convention.
// assuming getMethod() returns an appropriate Method reference isMessageSourceMethod(getMethod("getMessage")) = true isMessageSourceMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isMessageSourceMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
belongs to the set of
predefined message source methods by convention.
// assuming getMethod() returns an appropriate MethodDescriptor reference isMessageSourceMethod(getMethod("getMessage")) = true isMessageSourceMethod(getMethod("foo")) = false
method
- a MethodDescriptor referencepublic static boolean isResourceResolverMethod(@Nonnull java.lang.reflect.Method method)
Method
belongs to the set of
predefined resource resolver methods by convention.
// assuming getMethod() returns an appropriate Method reference isResourceResolverMethod(getMethod("resolveResource")) = true isResourceResolverMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isResourceResolverMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
belongs to the set of
predefined resource resolver methods by convention.
// assuming getMethod() returns an appropriate Method reference isResourceResolverMethod(getMethod("resolveResource")) = true isResourceResolverMethod(getMethod("foo")) = false
method
- a Method referencepublic static boolean isResourceResolverMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
belongs to the set of
predefined resource resolver methods by convention.
// assuming getMethod() returns an appropriate MethodDescriptor reference isResourceResolverMethod(getMethod("resolveResource")) = true isResourceResolverMethod(getMethod("foo")) = false
method
- a MethodDescriptor referencepublic static boolean isInstanceMethod(@Nonnull java.lang.reflect.Method method)
Method
is an instance method, i.e,
it is public and non-static.method
- a Method referencepublic static boolean isInstanceMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
is an instance method, i.e,
it is public and non-static.method
- a Method referencepublic static boolean isInstanceMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
is an instance method, i.e,
it is public and non-static.method
- a MethodDescriptor referencepublic static boolean isPlainMethod(@Nonnull java.lang.reflect.Method method)
Method
matches the following criteria:method
- a Method referencepublic static boolean isPlainMethod(@Nonnull java.lang.reflect.Method method, boolean removeAbstractModifier)
Method
matches the following criteria:method
- a Method referencepublic static boolean isPlainMethod(@Nonnull MethodDescriptor method)
MethodDescriptor
matches the following criteria:method
- a MethodDescriptor referencepublic static boolean isPropertyOfType(java.lang.Class<?> clazz, java.lang.String propertyName, java.lang.Class<?> type)
clazz
- The class which contains the propertypropertyName
- The property nametype
- The type to check@Nonnull public static java.lang.Object instantiateClass(@Nonnull java.lang.Class<?> clazz)
clazz
- target Class for which an object will be instantiatedBeanInstantiationException
- if an error occurs when creating the object@Nonnull public static java.lang.Object instantiate(@Nonnull java.lang.Class<?> clazz, @Nullable java.lang.Object[] args)
@Nullable public static java.lang.Object getPropertyValueOfNewInstance(@Nullable java.lang.Class<?> clazz, @Nullable java.lang.String propertyName, java.lang.Class<?> propertyType)
clazz
- The name of the class which contains the propertypropertyName
- The property namepropertyType
- The property typepublic static java.lang.Object getPropertyValueOfNewInstance(java.lang.Class<?> clazz, java.lang.String propertyName)
clazz
- The name of the class which contains the propertypropertyName
- The property namepublic static java.beans.PropertyDescriptor getPropertyDescriptorForValue(java.lang.Object instance, java.lang.Object propertyValue)
instance
- The instancepropertyValue
- The value of the property@Nullable public static java.lang.Class<?> getPropertyType(@Nullable java.lang.Class<?> clazz, @Nullable java.lang.String propertyName)
clazz
- The class which contains the propertypropertyName
- The name of the property@Nonnull public static java.beans.PropertyDescriptor[] getPropertiesOfType(@Nullable java.lang.Class<?> clazz, @Nullable java.lang.Class<?> propertyType)
clazz
- The class to retrieve the properties frompropertyType
- The type of the properties you wish to retrievepublic static java.beans.PropertyDescriptor[] getPropertiesAssignableToType(java.lang.Class<?> clazz, java.lang.Class<?> propertySuperType)
clazz
- The class to retrieve the properties frompropertySuperType
- The type of the properties you wish to retrievepublic static java.beans.PropertyDescriptor getProperty(java.lang.Class<?> clazz, java.lang.String propertyName, java.lang.Class<?> propertyType)
clazz
- The class to retrieve the property frompropertyName
- The name of the propertypropertyType
- The type of the propertypublic static java.lang.Object[] collectionToObjectArray(java.util.Collection<?> c)
c
- The collectionpublic static boolean isMatchBetweenPrimitiveAndWrapperTypes(@Nonnull java.lang.Class<?> leftType, @Nonnull java.lang.Class<?> rightType)
leftType
- rightType
- public static boolean isMatchBetweenPrimitiveAndWrapperTypes(@Nonnull java.lang.String leftType, @Nonnull java.lang.String rightType)
leftType
- rightType
- public static boolean isStaticProperty(@Nonnull java.lang.Class<?> clazz, @Nonnull java.lang.String propertyName)
Work out if the specified property is readable and static. Java introspection does not recognize this concept of static properties but Groovy does. We also consider public static fields as static properties with no getters/setters
clazz
- The class to check for static propertypropertyName
- The property namepublic static boolean isPublicStatic(@Nonnull java.lang.reflect.Method m)
m
- the method to be testedpublic static boolean isPublicStatic(@Nonnull java.lang.reflect.Field f)
f
- the field to be tested@Nonnull public static java.lang.String getGetterName(@Nonnull java.lang.String propertyName)
propertyName
- the name of the property@Nullable public static java.lang.Object getStaticPropertyValue(@Nonnull java.lang.Class<?> clazz, @Nonnull java.lang.String name)
Get a static property value, which has a public static getter or is just a public static field.
clazz
- The class to check for static propertyname
- The property name@Nullable public static java.lang.Object getPropertyOrStaticPropertyOrFieldValue(@Nonnull java.lang.Object obj, @Nonnull java.lang.String name)
Looks for a property of the reference instance with a given name.
If found its value is returned. We follow the Java bean conventions with augmentation for groovy support and static fields/properties. We will therefore match, in this order:
@Nullable public static java.lang.Object getFieldValue(@Nonnull java.lang.Object obj, @Nonnull java.lang.String name)
obj
- the instance that owns the fieldname
- the name of the file to lookup@Nullable public static java.lang.reflect.Field getField(@Nonnull java.lang.Object obj, @Nonnull java.lang.String name)
obj
- the instance that owns the fieldname
- the name of the file to lookup@Nullable public static java.lang.reflect.Field getField(@Nonnull java.lang.Class<?> clazz, @Nonnull java.lang.String name)
clazz
- the clazz that owns the fieldname
- the name of the file to lookuppublic static java.lang.reflect.Field[] getAllDeclaredFields(@Nonnull java.lang.Class<?> clazz)
Field
objects reflecting all the fields
declared by the class and its hierarchy, represented by this
Class
object. This includes public, protected, default
(package) access, and private fields, but excludes inherited fields.
The elements in the returned array are not sorted and are not in any particular order.
clazz
- the clazz that will be queried.Field
objects representing all the
declared fields of this class and its hierarchypublic static boolean isPublicField(@Nonnull java.lang.Object obj, @Nonnull java.lang.String name)
obj
- the instance that owns the fieldname
- the name of the file to lookuppublic static boolean isPropertyInherited(@Nullable java.lang.Class<?> clz, @Nonnull java.lang.String propertyName)
clz
- The class to checkpropertyName
- The property name@Nonnull public static java.util.Collection<?> createConcreteCollection(@Nonnull java.lang.Class<?> interfaceType)
interfaceType
- The interface@Nonnull public static java.lang.String getSetterName(@Nonnull java.lang.String propertyName)
propertyName
- The property namepublic static boolean isGetter(@Nullable java.lang.String name, @Nullable java.lang.Class[] args)
name
- True if its a Javabean propertyargs
- The arguments@Nullable public static java.lang.String getPropertyForGetter(@Nullable java.lang.String getterName)
getterName
- The getter name@Nullable public static java.lang.String getPropertyForSetter(@Nullable java.lang.String setterName)
setterName
- The setter namepublic static boolean isSetter(@Nullable java.lang.String name, @Nullable java.lang.Class[] args)
public static boolean isAssignableOrConvertibleFrom(@Nullable java.lang.Class<?> clazz, @Nullable java.lang.Class<?> type)
clazz
- type
- Class.isAssignableFrom(Class)
public static boolean getBooleanFromMap(@Nullable java.lang.String key, @Nullable java.util.Map<java.lang.String,java.lang.Object> map)
key
- The key that references the boolean valuemap
- The map to look inpublic static boolean isClassBelowPackage(@Nonnull java.lang.Class<?> clazz, @Nonnull java.util.List<?> packageList)
clazz
- The classpackageList
- The list of packagespublic static void setPropertiesOrFields(@Nonnull java.lang.Object bean, @Nonnull java.util.Map<java.lang.String,java.lang.Object> properties) throws PropertyException
This method will attempt setting a property using a matching
PropertyDescriptor
; next it will try direct field
access if the property was not found.
bean
- the target object on which properties will be setproperties
- names and values for properties to be setPropertyException
- if a property could be foundpublic static void setPropertiesOrFieldsNoException(@Nonnull java.lang.Object bean, @Nonnull java.util.Map<java.lang.String,java.lang.Object> properties)
This method will attempt setting a property using a matching
PropertyDescriptor
; next it will try direct field
access if the property was not found.
bean
- the target object on which properties will be setproperties
- names and values for properties to be setpublic static void setPropertyOrFieldValue(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name, @Nullable java.lang.Object value) throws PropertyException
This method will attempt setting a property using a matching
PropertyDescriptor
; next it will try direct field
access if the property was not found.
bean
- the target object on which the property will be setname
- the name of the property to setvalue
- the value to be setPropertyException
- if the property could not be foundpublic static void setPropertyOrFieldValueNoException(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name, @Nullable java.lang.Object value)
This method will attempt setting a property using a matching
PropertyDescriptor
; next it will try direct field
access if the property was not found.
bean
- the target object on which the property will be setname
- the name of the property to setvalue
- the value to be setPropertyException
- if the property could not be foundpublic static void setFieldsOrProperties(@Nonnull java.lang.Object bean, @Nonnull java.util.Map<java.lang.String,java.lang.Object> properties) throws FieldException
This method will attempt setting a property using direct field
access; next it will try a PropertyDescriptor
if a
matching field name was not found.
bean
- the target object on which properties will be setproperties
- names and values for properties to be setFieldException
- if the field could not be foundpublic static void setFieldsOrPropertiesNoException(@Nonnull java.lang.Object bean, @Nonnull java.util.Map<java.lang.String,java.lang.Object> properties)
This method will attempt setting a property using direct field
access; next it will try a PropertyDescriptor
if a
matching field name was not found.
bean
- the target object on which properties will be setproperties
- names and values for properties to be setpublic static void setFieldOrPropertyValue(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name, @Nullable java.lang.Object value) throws FieldException
This method will attempt setting a property using direct field
access; next it will try a PropertyDescriptor
if a
matching field name was not found.
bean
- the target object on which the property will be setname
- the name of the property to setvalue
- the value to be setFieldException
- if the property could not be foundpublic static void setFields(@Nonnull java.lang.Object bean, @Nonnull java.util.Map<java.lang.String,java.lang.Object> fields) throws FieldException
bean
- the target object on which field values will be setfields
- names and values of fields to be setFieldException
- if a field could not be foundpublic static void setFieldsNoException(@Nonnull java.lang.Object bean, @Nonnull java.util.Map<java.lang.String,java.lang.Object> fields)
bean
- the target object on which field values will be setfields
- names and values of fields to be setpublic static void setFieldValue(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name, @Nullable java.lang.Object value) throws FieldException
bean
- the target object on which the field will be setname
- the name of the field to setvalue
- the value to be setFieldException
- if the field could not be foundpublic static void setFieldValueNoException(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name, @Nullable java.lang.Object value)
bean
- the target object on which the field will be setname
- the name of the field to setvalue
- the value to be setFieldException
- if the field could not be foundpublic static void setProperties(@Nonnull java.lang.Object bean, @Nonnull java.util.Map<java.lang.String,java.lang.Object> properties) throws PropertyException
bean
- the target object on which properties will be setproperties
- names and values of properties to be setPropertyException
- if a property could not be foundpublic static void setPropertiesNoException(@Nonnull java.lang.Object bean, @Nonnull java.util.Map<java.lang.String,java.lang.Object> properties)
bean
- the target object on which properties will be setproperties
- names and values of properties to be setpublic static void setPropertyValue(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name, @Nullable java.lang.Object value) throws PropertyException
bean
- the target object on which the property will be setname
- the name of the property to setvalue
- the value to be setPropertyException
- if the property could not be found@Nullable public static java.lang.Object getPropertyValue(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name) throws PropertyException
bean
- the owner of the propertyname
- the name of the property to retrievePropertyException
- if the property could not be found@Nullable public static java.beans.PropertyDescriptor getPropertyDescriptor(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
Retrieve the property descriptor for the specified property of the
specified bean, or return null
if there is no such
descriptor.
bean
- Bean for which a property descriptor is requestedname
- name of the property for which a property descriptor
is requestedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
property cannot be found@Nullable public static java.beans.PropertyDescriptor getPropertyDescriptor(@Nonnull java.lang.Class<?> clazz, @Nonnull java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
Retrieve the property descriptor for the specified property of the
specified class, or return null
if there is no such
descriptor.
clazz
- class for which a property descriptor is requestedname
- name of the property for which a property descriptor
is requestedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
property cannot be found@Nonnull public static java.beans.PropertyDescriptor[] getPropertyDescriptors(@Nonnull java.lang.Class<?> beanClass)
Retrieve the property descriptors for the specified class, introspecting and caching them the first time a particular bean class is encountered.
beanClass
- Bean class for which property descriptors are requestedjava.lang.IllegalArgumentException
- if beanClass
is null@Nullable public static java.lang.reflect.Method getReadMethod(@Nonnull java.beans.PropertyDescriptor descriptor)
Return an accessible property getter method for this property,
if there is one; otherwise return null
.
descriptor
- Property descriptor to return a getter forpublic static boolean isReadable(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name)
Return true
if the specified property name identifies
a readable property on the specified bean; otherwise, return
false
.
bean
- Bean to be examinedname
- Property name to be evaluatedtrue
if the property is readable,
otherwise false
java.lang.IllegalArgumentException
- if bean
or name
is null
@Nullable public static java.lang.reflect.Method getWriteMethod(@Nonnull java.beans.PropertyDescriptor descriptor)
Return an accessible property setter method for this property,
if there is one; otherwise return null
.
descriptor
- Property descriptor to return a setter forpublic static boolean isWritable(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name)
Return true
if the specified property name identifies
a writable property on the specified bean; otherwise, return
false
.
bean
- Bean to be examinedname
- Property name to be evaluatedtrue
if the property is writable,
otherwise false
java.lang.IllegalArgumentException
- if bean
or name
is null
public static void setField(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name, @Nullable java.lang.Object value) throws java.lang.NoSuchFieldException, java.lang.IllegalAccessException, FieldException
bean
- Bean whose field is to be mutatedname
- Name of the field to be mutatedvalue
- The value to be set on the propertyjava.lang.IllegalAccessException
- if the caller does not have
access to the fieldjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.NoSuchFieldException
- if the named field cannot be foundFieldException
- if the field cannot be setpublic static void setProperty(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name, @Nullable java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, PropertyException
bean
- Bean whose property is to be mutatedname
- Name of the property to be mutatedvalue
- The value to be set on the propertyjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
property cannot be foundPropertyException
- if the property cannot be set@Nullable public static java.lang.Object getProperty(@Nonnull java.lang.Object bean, @Nonnull java.lang.String name) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException
bean
- Bean whose property is to be extractedname
- Possibly indexed and/or nested name of the property
to be extractedjava.lang.IllegalAccessException
- if the caller does not have
access to the property accessor methodjava.lang.IllegalArgumentException
- if bean
or
name
is nulljava.lang.reflect.InvocationTargetException
- if the property accessor method
throws an exceptionjava.lang.NoSuchMethodException
- if an accessor method for this
property cannot be found@Nullable public static java.lang.reflect.Method getReadMethod(@Nonnull java.lang.Class<?> clazz, @Nonnull java.beans.PropertyDescriptor descriptor)
Return an accessible property getter method for this property,
if there is one; otherwise return null
.
clazz
- The class of the read method will be invoked ondescriptor
- Property descriptor to return a getter for@Nullable public static java.lang.reflect.Method getWriteMethod(@Nonnull java.lang.Class<?> clazz, @Nonnull java.beans.PropertyDescriptor descriptor)
Return an accessible property setter method for this property,
if there is one; otherwise return null
.
clazz
- The class of the write method will be invoked ondescriptor
- Property descriptor to return a setter forpublic static void isTrue(boolean expression, java.lang.String message)
Validate that the argument condition is true
; otherwise
throwing an exception with the specified message. This method is useful when
validating according to an arbitrary boolean expression, such as validating a
primitive number or using your own custom validation expression.
isTrue( (i > 0), "The value must be greater than zero"); isTrue( myObject.isOk(), "The object is not OK");
expression
- the boolean expression to checkmessage
- the exception message if invalidjava.lang.IllegalArgumentException
- if expression is false
@Nullable public static java.lang.Object invokeInstanceMethod(@Nonnull java.lang.Object object, @Nonnull java.lang.String methodName)
@Nullable public static java.lang.Object invokeInstanceMethod(@Nonnull java.lang.Object object, @Nonnull java.lang.String methodName, java.lang.Object arg)
@Nullable public static java.lang.Object invokeInstanceMethod(@Nonnull java.lang.Object object, @Nonnull java.lang.String methodName, java.lang.Object... args)
@Nullable public static java.lang.Object invokeExactInstanceMethod(@Nonnull java.lang.Object object, @Nonnull java.lang.String methodName)
@Nullable public static java.lang.Object invokeExactInstanceMethod(@Nonnull java.lang.Object object, @Nonnull java.lang.String methodName, java.lang.Object arg)
@Nullable public static java.lang.Object invokeExactInstanceMethod(@Nonnull java.lang.Object object, @Nonnull java.lang.String methodName, java.lang.Object... args)
@Nullable public static java.lang.Object invokeStaticMethod(@Nonnull java.lang.Class<?> type, @Nonnull java.lang.String methodName)
@Nullable public static java.lang.Object invokeStaticMethod(@Nonnull java.lang.Class<?> type, @Nonnull java.lang.String methodName, java.lang.Object arg)
@Nullable public static java.lang.Object invokeStaticMethod(@Nonnull java.lang.Class<?> type, @Nonnull java.lang.String methodName, java.lang.Object... args)
@Nullable public static java.lang.Object invokeExactStaticMethod(@Nonnull java.lang.Class<?> type, @Nonnull java.lang.String methodName)
@Nullable public static java.lang.Object invokeExactStaticMethod(@Nonnull java.lang.Class<?> type, @Nonnull java.lang.String methodName, java.lang.Object arg)
@Nullable public static java.lang.Object invokeExactStaticMethod(@Nonnull java.lang.Class<?> type, @Nonnull java.lang.String methodName, java.lang.Object... args)
public static boolean hasMethodAnnotatedwith(@Nonnull java.lang.Object instance, @Nonnull java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
public static void invokeAnnotatedMethod(@Nonnull java.lang.Object instance, @Nonnull java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
@Nonnull public static java.lang.String getShortClassName(@Nullable java.lang.Object object, @Nonnull java.lang.String valueIfNull)
Gets the class name minus the package name for an Object
.
object
- the class to get the short name for, may be nullvalueIfNull
- the value to return if null@Nonnull public static java.lang.String getShortClassName(@Nullable java.lang.Class<?> cls)
Gets the class name minus the package name from a Class
.
cls
- the class to get the short name for.@Nonnull public static java.lang.String getShortClassName(@Nullable java.lang.String className)
Gets the class name minus the package name from a String.
The string passed in is assumed to be a class name - it is not checked.
className
- the className to get the short name for@Nonnull public static java.lang.String getPackageName(@Nullable java.lang.Object object, @Nonnull java.lang.String valueIfNull)
Gets the package name of an Object
.
object
- the class to get the package name for, may be nullvalueIfNull
- the value to return if null@Nonnull public static java.lang.String getPackageName(@Nullable java.lang.Class<?> cls)
Gets the package name of a Class
.
cls
- the class to get the package name for, may be null
.@Nonnull public static java.lang.String getPackageName(@Nullable java.lang.String className)
Gets the package name from a String
.
The string passed in is assumed to be a class name - it is not checked.
If the class is unpackaged, return an empty string.
className
- the className to get the package name for, may be null
@Nullable public static java.lang.Class<?>[] convertToTypeArray(@Nullable java.lang.Object[] args)
args
- the arguments