public static void properties2Object()

in connectors/rocketmq-connect-redis/src/main/java/org/apache/rocketmq/connect/redis/util/PropertyToObjectUtils.java [27:63]


    public static void properties2Object(final KeyValue p, final Object object)
        throws InvocationTargetException, IllegalAccessException {
        Method[] methods = object.getClass().getMethods();
        for (Method method : methods) {
            String mn = method.getName();
            if (mn.startsWith("set")) {
                String tmp = mn.substring(4);
                String first = mn.substring(3, 4);

                String key = first.toLowerCase() + tmp;
                String property = p.getString(key);
                if (property != null) {
                    Class<?>[] pt = method.getParameterTypes();
                    if (pt != null && pt.length > 0) {
                        String cn = pt[0].getSimpleName();
                        Object arg;
                        if (cn.equals("int") || cn.equals("Integer")) {
                            arg = Integer.parseInt(property);
                        } else if (cn.equals("long") || cn.equals("Long")) {
                            arg = Long.parseLong(property);
                        } else if (cn.equals("double") || cn.equals("Double")) {
                            arg = Double.parseDouble(property);
                        } else if (cn.equals("boolean") || cn.equals("Boolean")) {
                            arg = Boolean.parseBoolean(property);
                        } else if (cn.equals("float") || cn.equals("Float")) {
                            arg = Float.parseFloat(property);
                        } else if (cn.equals("String")) {
                            arg = property;
                        } else {
                            continue;
                        }
                        method.invoke(object, arg);
                    }
                }
            }
        }
    }