java.lang.Object
org.pushingpixels.substance.internal.contrib.randelshofer.quaqua.util.Methods

public class Methods extends Object
Methods contains convenience methods for method invocations using java.lang.reflect.
  • Method Details

    • invoke

      public static Object invoke(Object obj, String methodName) throws NoSuchMethodException
      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
    • 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 or METHOD_NOT_FOUND.
      Throws:
      NoSuchMethodException
    • invoke

      public static Object invoke(Object obj, String methodName, Class[] types, Object[] values) 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.
      types - The parameter types.
      values - The parameter values.
      Returns:
      The return value of the method.
      Throws:
      NoSuchMethodException
    • invokeStatic

      public static Object invokeStatic(Class clazz, String methodName) throws NoSuchMethodException
      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 or METHOD_NOT_FOUND.
      Throws:
      NoSuchMethodException
    • invokeStatic

      public static Object invokeStatic(String clazz, String methodName) throws NoSuchMethodException
      Invokes the specified static 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
    • invokeStatic

      public static Object invokeStatic(Class clazz, String methodName, Class[] types, Object[] values) throws NoSuchMethodException
      Invokes the specified static 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
    • invokeStatic

      public static Object invokeStatic(String clazz, String methodName, Class[] types, Object[] values) throws NoSuchMethodException
      Invokes the specified static 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
    • invokeStatic

      public static Object invokeStatic(String clazz, String methodName, Class type, Object value) throws NoSuchMethodException
      Invokes the specified static method if it exists.
      Parameters:
      clazz - The class on which to invoke the method.
      methodName - The name of the method.
      type - The parameter types.
      value - The parameter values.
      Returns:
      The return value of the method.
      Throws:
      NoSuchMethodException
    • invokeStatic

      public static Object invokeStatic(String clazz, String methodName, Class[] types, Object[] values, Object defaultValue)
      Invokes the specified static 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.
    • invokeStatic

      public static Object invokeStatic(Class clazz, String methodName, Class type, Object value) throws NoSuchMethodException
      Invokes the specified static method 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 or the default value if the method does not exist or is not accessible.
      Throws:
      NoSuchMethodException
    • invokeGetter

      public static int invokeGetter(Object obj, String methodName, int defaultValue)
      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

      public static long invokeGetter(Object obj, String methodName, long defaultValue)
      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

      public static boolean invokeGetter(Object obj, String methodName, boolean defaultValue)
      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

      public static Object invokeGetter(Object obj, String methodName, Object defaultValue)
      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

      public static boolean invokeStaticGetter(Class clazz, String methodName, boolean defaultValue)
      Invokes the specified getter method if it exists.
      Parameters:
      clazz - The class 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
    • invokeIfExists

      public static void invokeIfExists(Object obj, String methodName)
      Invokes the specified setter method if it exists.
      Parameters:
      obj - The object on which to invoke the method.
      methodName - The name of the method.
    • invokeIfExists

      public static void invokeIfExists(Object obj, String methodName, int newValue)
      Invokes the specified setter method if it exists.
      Parameters:
      obj - The object on which to invoke the method.
      methodName - The name of the method.
    • invokeIfExists

      public static void invokeIfExists(Object obj, String methodName, float newValue)
      Invokes the specified setter method if it exists.
      Parameters:
      obj - The object on which to invoke the method.
      methodName - The name of the method.
    • invokeIfExists

      public static void invokeIfExists(Object obj, String methodName, boolean newValue)
      Invokes the specified method if it exists.
      Parameters:
      obj - The object on which to invoke the method.
      methodName - The name of the method.
    • invokeIfExists

      public static void invokeIfExists(Object obj, String methodName, Class parameterClass, Object newValue)
      Invokes the specified setter method if it exists.
      Parameters:
      obj - The object on which to invoke the method.
      methodName - The name of the method.
    • invokeIfExistsWithEnum

      public static void invokeIfExistsWithEnum(Object obj, String methodName, String enumClassName, String enumValueName)
      Invokes the specified setter method if it exists.
      Parameters:
      obj - The object on which to invoke the method.
      methodName - The name of the method.
    • newInstance

      Invokes the specified constructor if it exists.
      Parameters:
      clazz - The Class on which to invoke the constructor.
      types - The parameter types of the constructor.
      values - The parameter values of the constructor.
      Throws:
      NoSuchMethodException
      InstantiationException
      IllegalAccessException
      InvocationTargetException