Class Methods
java.lang.Object
org.monte.media.util.Methods
Methods contains convenience methods for method invocations using
java.lang.reflect.
- Author:
- Werner Randelshofer
-
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectInvokes the specified accessible parameterless method if it exists.static ObjectInvokes the specified setter method if it exists.static ObjectInvokes the specified setter method if it exists.static ObjectInvokes the specified method if it exists.static ObjectInvokes the specified setter method if it exists.static ObjectInvokes the specified setter method if it exists.static ObjectInvokes the specified accessible method with a string parameter if it exists.static booleaninvokeGetter(Object obj, String methodName, boolean defaultValue) Invokes the specified getter method if it exists.static intinvokeGetter(Object obj, String methodName, int defaultValue) Invokes the specified getter method if it exists.static longinvokeGetter(Object obj, String methodName, long defaultValue) Invokes the specified getter method if it exists.static ObjectinvokeGetter(Object obj, String methodName, Object defaultValue) Invokes the specified getter method if it exists.static voidinvokeIfExists(Object obj, String methodName) Invokes the specified setter method if it exists.static voidinvokeIfExists(Object obj, String methodName, boolean newValue) Invokes the specified method if it exists.static voidinvokeIfExists(Object obj, String methodName, float newValue) Invokes the specified setter method if it exists.static voidinvokeIfExists(Object obj, String methodName, Class<?> clazz, Object newValue) Invokes the specified setter method if it exists.static voidinvokeIfExistsWithEnum(Object obj, String methodName, String enumClassName, String enumValueName) Invokes the specified setter method if it exists.static ObjectinvokeStatic(Class<?> clazz, String methodName) Invokes the specified accessible parameterless method if it exists.static ObjectinvokeStatic(Class<?> clazz, String methodName, Class<?>[] types, Object[] values) Invokes a static method on the specified class with the given parameter types and values.static ObjectinvokeStatic(Class<?> clazz, String methodName, Class<?> type, Object value) Invokes the specified method with a single parameter if it exists.static ObjectinvokeStatic(String clazz, String methodName) Invokes the specified accessible parameterless method if it exists.static ObjectinvokeStatic(String clazz, String methodName, Class<?>[] types, Object[] values) Invokes the specified parameterless method if it exists.static ObjectinvokeStatic(String clazz, String methodName, Class<?>[] types, Object[] values, Object defaultValue) Invokes the specified parameterless method if it exists.static booleaninvokeStaticGetter(Class<?> clazz, String methodName, boolean defaultValue) Invokes the specified getter method if it exists.
-
Method Details
-
invoke
Invokes the specified accessible parameterless method if it exists.- Parameters:
obj- The object on which to invoke the method.methodName- The name of the method.- Returns:
- The return value of the method.
- Throws:
NoSuchMethodException- if the method does not exist or is not accessible.
-
invoke
public static Object invoke(Object obj, String methodName, String stringParameter) throws NoSuchMethodException Invokes the specified accessible method with a string parameter if it exists.- Parameters:
obj- The object on which to invoke the method.methodName- The name of the method.stringParameter- The String parameter.- Returns:
- The return value of the method.
- Throws:
NoSuchMethodException- if the method does not exist or is not accessible.
-
invokeStatic
Invokes the specified accessible parameterless method if it exists.- Parameters:
clazz- The class on which to invoke the method.methodName- The name of the method.- Returns:
- The return value of the method.
- Throws:
NoSuchMethodException- if the method does not exist or is not accessible.
-
invokeStatic
Invokes the specified accessible parameterless method if it exists.- Parameters:
clazz- The class on which to invoke the method.methodName- The name of the method.- Returns:
- The return value of the method.
- Throws:
NoSuchMethodException- if the method does not exist or is not accessible.
-
invokeStatic
public static Object invokeStatic(Class<?> clazz, String methodName, Class<?> type, Object value) throws NoSuchMethodException Invokes the specified method with a single parameter if it exists.- Parameters:
clazz- The class on which to invoke the method.methodName- The name of the method.type- The parameter type.value- The parameter value.- Returns:
- The return value of the method.
- Throws:
NoSuchMethodException- if the method does not exist or is not accessible.
-
invokeStatic
public static Object invokeStatic(Class<?> clazz, String methodName, Class<?>[] types, Object[] values) throws NoSuchMethodException Invokes a static method on the specified class with the given parameter types and values.- Parameters:
clazz- The class on which to invoke the method.methodName- The name of the method to invoke.types- The parameter types of the method.values- The parameter values to pass to the method.- Returns:
- The return value of the invoked method.
- Throws:
NoSuchMethodException- if the method does not exist or is not accessible.
-
invokeStatic
public static Object invokeStatic(String clazz, String methodName, Class<?>[] types, Object[] values) throws NoSuchMethodException Invokes the specified parameterless method if it exists.- Parameters:
clazz- The class on which to invoke the method.methodName- The name of the method.types- The parameter types.values- The parameter values.- Returns:
- The return value of the method.
- Throws:
NoSuchMethodException- if the method does not exist or is not accessible.
-
invokeStatic
public static Object invokeStatic(String clazz, String methodName, Class<?>[] types, Object[] values, Object defaultValue) Invokes the specified parameterless method if it exists.- Parameters:
clazz- The class on which to invoke the method.methodName- The name of the method.types- The parameter types.values- The parameter values.defaultValue- The default value.- Returns:
- The return value of the method or the default value if the method does not exist or is not accessible.
-
invokeGetter
Invokes the specified getter method if it exists.- Parameters:
obj- The object on which to invoke the method.methodName- The name of the method.defaultValue- This value is returned, if the method does not exist.- Returns:
- The value returned by the getter method or the default value.
-
invokeGetter
Invokes the specified getter method if it exists.- Parameters:
obj- The object on which to invoke the method.methodName- The name of the method.defaultValue- This value is returned, if the method does not exist.- Returns:
- The value returned by the getter method or the default value.
-
invokeGetter
Invokes the specified getter method if it exists.- Parameters:
obj- The object on which to invoke the method.methodName- The name of the method.defaultValue- This value is returned, if the method does not exist.- Returns:
- The value returned by the getter method or the default value.
-
invokeGetter
Invokes the specified getter method if it exists.- Parameters:
obj- The object on which to invoke the method.methodName- The name of the method.defaultValue- This value is returned, if the method does not exist.- Returns:
- The value returned by the getter method or the default value.
-
invokeStaticGetter
Invokes the specified getter method if it exists.- Parameters:
clazz- The object on which to invoke the method.methodName- The name of the method.defaultValue- This value is returned, if the method does not exist.- Returns:
- The value returned by the getter method or the default value.
-
invoke
public static Object invoke(Object obj, String methodName, boolean newValue) throws NoSuchMethodException Invokes the specified setter method if it exists.- Parameters:
obj- The object on which to invoke the method.methodName- The name of the method.- Throws:
NoSuchMethodException
-
invoke
public static Object invoke(Object obj, String methodName, int newValue) throws NoSuchMethodException Invokes the specified method if it exists.- Parameters:
obj- The object on which to invoke the method.methodName- The name of the method.- Throws:
NoSuchMethodException
-
invoke
public static Object invoke(Object obj, String methodName, float newValue) throws NoSuchMethodException Invokes the specified setter method if it exists.- Parameters:
obj- The object on which to invoke the method.methodName- The name of the method.- Throws:
NoSuchMethodException
-
invoke
public static Object invoke(Object obj, String methodName, Class<?> clazz, Object newValue) throws NoSuchMethodException Invokes the specified setter method if it exists.- Parameters:
obj- The object on which to invoke the method.methodName- The name of the method.- Throws:
NoSuchMethodException
-
invoke
public static Object invoke(Object obj, String methodName, Class<?>[] clazz, Object... newValue) throws NoSuchMethodException Invokes the specified setter method if it exists.- Parameters:
obj- The object on which to invoke the method.methodName- The name of the method.- Throws:
NoSuchMethodException
-
invokeIfExists
-
invokeIfExists
-
invokeIfExists
-
invokeIfExists
-
invokeIfExistsWithEnum
-