• GetSetUtil


    package com.jpush;
    
    import cn.jpush.statistics.excel.model.AdSettlementInfoModel;
    import cn.jpush.statistics.model.entity.AdSettlementInfo;
    
    import java.lang.reflect.Field;
    import java.lang.reflect.Method;
    import java.util.HashMap;
    import java.util.Map;
    
    public class GetSetUtil {
        public static void main(String[] args) {
           setMethod(AdSettlementInfoModel.class,AdSettlementInfo.class,"model","info");
    
        }
        //            hiveData.setCpc(result.get("cpc"));
        private static void mapToPojo(Class clazz,String target , String mapGet){
            Field[] fields = clazz.getDeclaredFields();
            for (Field field : fields) {
                String name = field.getName();
                char first = name.charAt(0);
                String substring = name.substring(1);
                String pre = Character.toUpperCase(first)+substring;
                System.out.println(target+pre+"("+mapGet+"(""+name+""));");
    //            System.out.println("hiveData.set"+pre+"(result.get(""+name+""));");
            }
        }
    
        
        private static void setMethod(Class sourceClass,Class targetClass,String sourceName,String targeName){
            Method[] sourceMethods = sourceClass.getMethods();
            Method[] targetMethods = targetClass.getMethods();
    
            Map<String,Method> sourceMethodMap = new HashMap<>();
            Map<String,Method> targetMethodMap = new HashMap<>();
            for (Method sourceMethod : sourceMethods) {
                sourceMethodMap.put(sourceMethod.getName(),sourceMethod);
            }
    
            for (Method targetMethod : targetMethods) {
                targetMethodMap.put(targetMethod.getName(),targetMethod);
            }
    
    
            for (Map.Entry<String, Method> stringMethodEntry : sourceMethodMap.entrySet()) {
                Method method = targetMethodMap.get(stringMethodEntry.getKey());
                if(method == null){
                    continue;
                }
                String name = method.getName();
                if(name.startsWith("get") && !"getClass".equals(name)){
                    String setName = name.substring(3);
                    System.out.println(targeName+".set"+setName+"("+sourceName+"."+name+"());");
                }
            }
            
            
        }
    }
  • 相关阅读:
    Redis
    Zookeeper的安装配置及基本开发
    【Unity Shader】新书封面 — Low Polygon风格的渲染
    Hive基本原理及环境搭建
    Hadoop开发环境搭建
    java常用排序算法
    企业人事管理系统项目拾金
    Linux27:分区、格式化与修复
    Linux26:查询磁盘和监控系统资源
    Linux25:文件系统特点与XFS文件系统
  • 原文地址:https://www.cnblogs.com/dongma/p/13865522.html
Copyright © 2020-2023  润新知