• 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+"());");
                }
            }
            
            
        }
    }
  • 相关阅读:
    《CSOL大灾变》Mobile开发记录——武器音效部分
    MobilePBRLighting优化思路2
    《CSOL大灾变》开发记录——武器购买逻辑开发
    《CSOL大灾变》Mobile开发进度记录——扔掉与拾取武器的逻辑
    《CSOL大灾变》Mobile开发进度记录——武器购买界面设计
    Godot的场景树
    Unity3D发布Android注意事项
    Unity3D——关于质量的设置
    NifytGUI——ListBox控件
    python-PEP8编码规范-中文简版
  • 原文地址:https://www.cnblogs.com/dongma/p/13865522.html
Copyright © 2020-2023  润新知