Java Method Call invokePrimivite(Object entity, Method writeMethod, Class propertyType, String propertyValue)

Here you can find the source of invokePrimivite(Object entity, Method writeMethod, Class propertyType, String propertyValue)

Description

invoke Primivite

License

Apache License

Declaration

public static void invokePrimivite(Object entity, Method writeMethod, Class propertyType, String propertyValue)
        throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;

public class Main {

    public static void invokePrimivite(Object entity, Method writeMethod, Class propertyType, String propertyValue)
            throws Exception {
        if (isByte(propertyType)) {
            writeMethod.invoke(entity, Byte.parseByte(propertyValue));
        } else if (isShort(propertyType)) {
            writeMethod.invoke(entity, Short.parseShort(propertyValue));
        } else if (isInt(propertyType)) {
            writeMethod.invoke(entity, Integer.parseInt(propertyValue));
        } else if (isLong(propertyType)) {
            writeMethod.invoke(entity, Long.parseLong(propertyValue));
        } else if (isFloat(propertyType)) {
            writeMethod.invoke(entity, Float.parseFloat(propertyValue));
        } else if (isDouble(propertyType)) {
            writeMethod.invoke(entity, Double.parseDouble(propertyValue));
        } else if (isBoolean(propertyType)) {
            writeMethod.invoke(entity, Boolean.parseBoolean(propertyValue));
        } else if (isChar(propertyType)) {
            writeMethod.invoke(entity, propertyValue.charAt(0));
        }/*from  w ww.ja  va  2s  .c  o m*/
    }

    public static boolean isByte(Class clazz) {
        return (clazz == Byte.class) || (clazz == byte.class);
    }

    public static boolean isShort(Class clazz) {
        return (clazz == Short.class) || (clazz == short.class);
    }

    public static boolean isInt(Class clazz) {
        return (clazz == Integer.class) || (clazz == int.class);
    }

    public static boolean isLong(Class clazz) {
        return (clazz == Long.class) || (clazz == long.class);
    }

    public static boolean isFloat(Class clazz) {
        return (clazz == Float.class) || (clazz == float.class);
    }

    public static boolean isDouble(Class clazz) {
        return (clazz == Double.class) || (clazz == double.class);
    }

    public static boolean isBoolean(Class clazz) {
        return (clazz == Boolean.class) || (clazz == boolean.class);
    }

    public static boolean isChar(Class clazz) {
        return (clazz == Character.class) || (clazz == char.class);
    }
}

Related

  1. invokeNonArgMethod(Object object, String methodName)
  2. invokeObjectMethod(Object object, String name, Class paramTypes[], Object args[])
  3. invokeOrBailOut(Object invokee, Method method, Object[] params)
  4. invokeParameterlessMethod(T theObject, String methodName)
  5. invokePrepare(Object instance)
  6. invokePrivate(Class clazz, Object instance, String methodName, Class[] argTypes, Object[] args)
  7. invokePrivate(String name, final Object obj, Object[] objects)
  8. invokePrivateMethod(Method method, Object object, Object... args)
  9. invokePrivateMethod(Object instance, String name, Object... args)