public class MetaUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static List<Class<?>> |
SIMPLE_RETURN_TYPE_LIST
The simple return type list
|
| Constructor and Description |
|---|
MetaUtil() |
| Modifier and Type | Method and Description |
|---|---|
static List<Class<?>> |
allExtendedClassesOf(Class<?> classz)
All classes that the given class extends
|
static List<Field> |
allFieldsOf(Class<?> classz)
All fields that can be found on an object of the given class
|
static List<Method> |
allMethodsOf(Class<?> classz)
All methods that can be invoked on an object of the given class
|
static List<Field> |
allSuperFieldsOf(Class<?> classz)
All fields that can be found on an object's hierarchy other than itself
of the given class
|
void |
assignFromHierarchy(Object obj)
For each field that the subclass has, if superclasses also have it, then
fetch that value from hierarchy and set here.
|
static int |
availablePort(int startPort,
int maxCount)
Get available server port from the given port inclusive, until the max
count.
|
static Map<String,Object> |
classNameObjectMap(Object... objects)
Returns a map containing the object's class name as key with the object
itself as value.
|
void |
copyFields(Object dst,
Object src)
For each field that the destination has, if source also have it, then
fetch that value from source and set in destination.
|
static Map<String,Object> |
createMap(String key,
Object value)
Returns a new map which has single entry with the given key and value.
|
static Map<String,Object> |
createParamMap(Object... params)
Create a params map from given varargs.
|
static Map<String,String> |
createPropsMap(String... args)
Create a property map from given varargs.
|
static void |
disableSslCertificates()
Disables SSL certificates checks
|
static Map<String,Object> |
fieldDataMap(Object target,
boolean prependClassName,
String methodPrefix,
List<Class<?>> returnTypeList)
Get the map of all the return values of all the methods starting with
given prefix with the given return types of the given bean.
|
static Field |
findFirstField(Class<?> clazz,
String fieldName)
Finds the first field by this name or null if not found.
|
static Field |
findFirstFieldByType(Class<?> clazz,
String typeName)
Finds the first field by its type name or null if not found.
|
static Method |
findFirstMethod(Class<?> clazz,
String methodName)
Finds the first method by this name or null if not found.
|
static Method |
findFirstMethod(Class<?> classz,
String methodName,
int totalArguments)
Find first method matching name and no.
|
static Method |
findFirstMethodEndsWithAndReturns(Class<?> clazz,
String methodName,
Class<?> returnType)
Finds the first method ending by this name and having this return type or
null if not found.
|
static Method |
findFirstMethodStartsWith(Class<?> clazz,
String methodName)
Finds the first method starting by this name or null if not found.
|
static Field |
findFirstSuperField(Class<?> clazz,
String fieldName)
Finds the first super field by this name or null if not found.
|
static Method |
findSetter(Class<?> classz,
String propertyName)
Finds the setter method for the property or null if not found.
|
static String |
getResourceAsString(String resourceName)
Get the resource as string.
|
static long |
hash(String string)
Computes a long hash for this string.
|
static void |
registerAsMBean(Object bean)
Register the instance as MBean.
|
static void |
registerAsMBean(Object bean,
String objectName)
Register the instance as MBean with given name.
|
static Object |
runNestedMethod(Object target,
String nestedMethod)
Run the nested method on the target object.
|
static Map<String,Object> |
runNestedMethodsSilently(Object target,
String nestedMethods)
Run the nested methods silently on the target object.
|
static void |
setPropertyIfExists(Object obj,
String propertyName,
Object propertyValue)
Sets the given property if exists with the given value.
|
static void |
shuffleArray(Object array)
Shuffles the given array, if it is array.
|
static Map<String,Object> |
simpleFieldDataMap(Object target,
boolean prependClassName)
Get the map of all the return values of all the methods with no arguments
with simple return types of the given bean.
|
public static Map<String,Object> createParamMap(Object... params)
params - the paramspublic static String getResourceAsString(String resourceName)
resourceName - the resource namepublic static void registerAsMBean(Object bean) throws JMException
bean - the beanJMException - implicitpublic static void registerAsMBean(Object bean, String objectName) throws JMException
bean - the beanobjectName - the object nameJMException - implicitpublic static Method findFirstMethodStartsWith(Class<?> clazz, String methodName)
clazz - the classmethodName - the method namepublic static Method findFirstMethodEndsWithAndReturns(Class<?> clazz, String methodName, Class<?> returnType)
clazz - the classmethodName - the method namereturnType - the return typepublic static Method findFirstMethod(Class<?> clazz, String methodName)
clazz - the classmethodName - the method namepublic static Method findFirstMethod(Class<?> classz, String methodName, int totalArguments)
classz - the classmethodName - the method nametotalArguments - the total no. of argumentspublic static List<Class<?>> allExtendedClassesOf(Class<?> classz)
classz - the classpublic static List<Method> allMethodsOf(Class<?> classz)
classz - the classpublic static Field findFirstField(Class<?> clazz, String fieldName)
clazz - the classfieldName - the field namepublic static Field findFirstSuperField(Class<?> clazz, String fieldName)
clazz - the classfieldName - the field namepublic static Field findFirstFieldByType(Class<?> clazz, String typeName)
clazz - the classtypeName - the field type simple namepublic static List<Field> allFieldsOf(Class<?> classz)
classz - the classpublic static List<Field> allSuperFieldsOf(Class<?> classz)
classz - the classpublic static Method findSetter(Class<?> classz, String propertyName)
classz - the classpropertyName - the property namepublic static void setPropertyIfExists(Object obj, String propertyName, Object propertyValue)
obj - the objectpropertyName - the property namepropertyValue - the property valuepublic static Map<String,Object> fieldDataMap(Object target, boolean prependClassName, String methodPrefix, List<Class<?>> returnTypeList)
target - the target objectprependClassName - the prepend class namemethodPrefix - the method prefixreturnTypeList - the return types listpublic static Map<String,Object> simpleFieldDataMap(Object target, boolean prependClassName)
target - the target objectprependClassName - the prepend class namepublic static Map<String,Object> classNameObjectMap(Object... objects)
objects - the objectspublic static Map<String,Object> createMap(String key, Object value)
key - the keyvalue - the valuepublic static Map<String,String> createPropsMap(String... args)
args - the argumentspublic static void shuffleArray(Object array)
array - the array to shufflepublic static int availablePort(int startPort,
int maxCount)
startPort - the start portmaxCount - the max countpublic static Object runNestedMethod(Object target, String nestedMethod) throws ReflectiveOperationException, ScriptException
target - the target objectnestedMethod - the nested methodScriptException - when there is a problem in scriptReflectiveOperationException - when a problem in reflectionpublic static Map<String,Object> runNestedMethodsSilently(Object target, String nestedMethods)
target - the target objectnestedMethods - the nested methods separated by ;;public static void disableSslCertificates()
throws GeneralSecurityException
GeneralSecurityException - if anything wrong happenspublic static long hash(String string)
string - the stringpublic void assignFromHierarchy(Object obj)
obj - the objectCopyright © 2016. All rights reserved.