映射方法将对象转换成map打印出来方法

package com.hopechart.platform.provider.test;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.Random;
import java.util.Set;

import com.fasterxml.jackson.module.scala.introspect.PropertyDescriptor;
import com.hopechart.dataquery.typecrane.ChassisLTDataPer10Min;
import com.hopechart.dataquery.typecrane.ChassisLTDataPer1Sec;
import com.hopechart.dataquery.typecrane.ChassisLTDataPer5Min;
import com.hopechart.dataquery.typecrane.CraneLTDataPer1Sec;
import com.hopechart.dataquery.typecrane.CraneLTDataPer5Min;
import com.hopechart.dataquery.typecrane.CraneLTDataSwitch;
import com.hopechart.platform.provider.component.cc.util.FormatCanData;
import com.hopechart.platform.provider.component.cc.vo.crane.CDBase;
import com.hopechart.platform.provider.component.cc.vo.crane.CDSwitch;
import com.hopechart.platform.provider.component.cc.vo.crane.CDSwitchDown;
import com.hopechart.platform.provider.component.cc.vo.crane.ResultCraneData;
import com.hopechart.platform.provider.component.log.annotation.FieldMeta;
import com.hopechart.platform.provider.component.redis.pojo.MonitorBaseData;
import com.hopechart.platform.provider.component.redis.pojo.crane.CBaseWatch;
import com.hopechart.platform.provider.component.redis.pojo.crane.CGPSWatch;
import com.hopechart.platform.provider.component.redis.pojo.crane.CSwitchWatch;
import com.hopechart.platform.provider.component.redis.pojo.crane.CWorkCondWatch;
import com.hopechart.platform.provider.component.redis.pojo.crane.CWorkWatch;
import com.hopechart.platform.provider.component.redis.pojo.crane.CraneMonitorData;
import com.hopechart.platform.provider.component.redis.pojo.crane.StockEqMonitorInfoVo;
import com.hopechart.platform.provider.modules.carTrack.pojo.CarTrackParamVo;
import com.hopechart.platform.provider.modules.video.pojo.LoginYSYParam;
import com.hopechart.platform.provider.util.DataUtil;
import com.hopechart.platform.provider.util.MGDecoder;
import com.hopechart.platform.provider.util.TimeUtil;

public class test {
public static void main(String[] args) {

CSwitchWatch s = new CSwitchWatch();

// for(int i = 8; i<16; i ++){
// System.out.println(“String val”+(i)+" = cd.get(FormatCanData.formatCanDateKey(Constant.cId18ff6831, @!"+i+"@!, @!@!))+@!@!;");
// System.out.println(“this.switch”+(i)+" = checkSwitchData(val"+i+") ? invalidData : stateTags[Integer.parseInt(val"+i+")];");
// }
//LoginYSYParam s = new LoginYSYParam();
// s.setLoginType((byte)0);
// s.setUserName(“test”);
// s.setUserPassword(“12344”);
getFiledName(s);
// System.out.println(formatHttpGetParam(s));
// test123 s = new test123();
// getFiledName(s);
// Set r = new LinkedHashSet(10);
// Random random = new Random();
//
// while (r.size() < 10 ) {
// int i = random.nextInt(5);
// r.add(i);
// }
// System.out.println(Arrays.toString(r.toArray()));
}

private static String[] getFiledName(Object o){
Field[] fields=o.getClass().getDeclaredFields();
String[] fieldNames=new String[fields.length];
for(int i=0;i<fields.length;i++){

	String fieldName=fields[i].getName();
	 String firstLetter = fieldName.substring(0, 1).toUpperCase(); 
	System.out.println(" originalMap.put(!@"+fieldName+"!@,data.get"+firstLetter + fieldName.substring(1)+"());");
	// System.out.println("re.put(@!"+fieldName+"@!, monitor.get"+firstLetter + fieldName.substring(1)+"() != null ? monitor.get"+firstLetter + fieldName.substring(1)+"() : @!@!);");
	// String str = "upBaseList.add(new CarTrackParamVo(codeMap.get(Constant."+fieldName+"Id).getCodeName(), data.getBaseSaveTime(), data.getBaseSaveTime(),data.get"+ firstLetter + fieldName.substring(1)+"(), null, null,this.carVin,Constant.code_type_base,Constant."+fieldName+"Id + 12));";
	// String str = "downWorkCondList.add(new CarTrackParamVo(codeMap.get(Constant."+fieldName+"Id).getCodeName(), data.getWorkCondSaveTime(), data.getWorkCondSaveTime(),data.get"+ firstLetter + fieldName.substring(1)+"(), null, null,this.carVin,Constant.code_type_work_cond,Constant."+fieldName+"Id + 12));";

//
//String str = “downSwitchList.add(new CarTrackParamVo(codeMap.get(Constant.”+fieldName+“Id).getCodeName(), data.getSwitchSaveTime(), data.getSwitchSaveTime(),data.get”+ firstLetter + fieldName.substring(1)+"(), null, null,this.carVin,Constant.code_type_switch,Constant."+fieldName+“Id + 12));”;
// String str = “downWorkList.add(new CarTrackParamVo(codeMap.get(Constant.”+fieldName+“Id).getCodeName(), data.getWorkSaveTime(), data.getWorkSaveTime(),data.get”+ firstLetter + fieldName.substring(1)+"(), null, null,this.carVin,Constant.code_type_work,Constant."+fieldName+“Id + 12));”;
// System.out.println(str);’

// String str = “switchMap.put(Constant.”+fieldName+“Id, cd.getValueByID(Constant.”+fieldName+“Id));”;
// System.out.println(str);
// System.out.println(“this.”+fieldName +" = cd.get"+ firstLetter + fieldName.substring(1)+"();");
//System.out.println(“this.”+fieldName +" = defaultData;");
//System.out.println(“Long " +fieldName+ " = len >= 4 ? MGDecoder.byte4ToLongByBE(buf, 0) : null;”);
// String getter = “data.set” + firstLetter + fieldName.substring(1)+"("+fieldName+");";
// System.out.println(getter);
//String getter = null;
// if(i < 33){
// getter = “data.set” + firstLetter + fieldName.substring(1)+"(switchWatch.get"+firstLetter + fieldName.substring(1)+"() != null ? switchWatch.get"+firstLetter + fieldName.substring(1)+"().toString(): Constant.NO_DATA_TAG);";
// }else{
// getter = “data.set” + firstLetter + fieldName.substring(1)+"(switchWatch.get"+firstLetter + fieldName.substring(1)+"() != null ? CSwitchWatch.stateTags[switchWatch.get"+firstLetter + fieldName.substring(1)+"().intValue()]: Constant.NO_DATA_TAG);";
// }
//
// this.switch158 = checkSwitchData(cd.getValueByID(Constant.switch158Id)) ? invalidData
// : alamTags[Integer.parseInt(cd
// .getValueByID(Constant.switch158Id))];
//getter = “this.” +fieldName+" = checkSwitchData(cd.getValueByID(Constant."+fieldName+“Id)) ? invalidData :cd.getValueByID(Constant.”+fieldName+“Id);”;
//String getter = “re.”+fieldName+" = per.get"+ firstLetter + fieldName.substring(1)+"();";
//System.out.println(getter);
// String getter = “data.set”+firstLetter + fieldName.substring(1)+"(Constant.NO_DATA_TAG);" ;
// String getter = “data.set”+firstLetter + fieldName.substring(1)+"(stockWatchData.get"+firstLetter + fieldName.substring(1)+"()!= null ? String.valueOf(stockWatchData.get"+firstLetter + fieldName.substring(1)+"()):Constant.NO_DATA_TAG);" ;
// System.out.println(getter);
//System.out.println(withinRange);
// System.out.println(" if (per.get"+ firstLetter + fieldName.substring(1)+"() != null) {");
// System.out.println(“re.”+fieldName+" = (DataUtil.byteBoundary(DataUtil.parseInt(per.get"+firstLetter + fieldName.substring(1)+"()), DataUtil.BYTE_BOUNDARY_WORD) ? “);
// System.out.println(“invalidData”);
// System.out.println(”: String.valueOf(per.get"+firstLetter + fieldName.substring(1)+"()));");
// System.out.println("}else{");
// System.out.println(“re.”+ fieldName+"= invalidData ;" );
// System.out.println("}");
// System.out.println(“re.”+fieldName+"= DataUtil.byteBoundary(per.get"+firstLetter + fieldName.substring(1)+"(),DataUtil.BYTE_BOUNDARY_BYTE_FF) ? invalidData"+
// “: String.valueOf(per.get”+firstLetter + fieldName.substring(1)+"());");
// System.out.println(“case Constant.”+fields[i].getName()+“Id:”);
// System.out.println(“re.”+fieldName+" = per.get"+firstLetter + fieldName.substring(1)+"();");
// System.out.println( " " + fields[i].getName()+ " = ((Number) value).longValue();");
// System.out.println( " break;");
// System.out.println(“this.”+fieldName+" = cd.getValueByID(Constant."+fieldName+“Id);”);
// System.out.println(“switchMap.put(Constant.”+fieldName+“Id, cd.getValueByID(Constant.”+fieldName+“Id));”);
//状态数据
//System.out.println(“data.set”+firstLetter + fieldName.substring(1)+"(switchWatch.get"+firstLetter + fieldName.substring(1)+"() != null ? CDSwitch.stateTags[switchWatch.get"+firstLetter + fieldName.substring(1)+"().intValue()]: Constant.NO_DATA_TAG);");
// System.out.println(“case Constant.”+fieldName+"😊;
//
// System.out.println(“productModel = Constant.”+fieldName+"_STR;");
// System.out.println(“break;”);
// System.out.println(" public static final String “+fieldName+“STR = ‘"+fieldName.replace("CCWC”, “”)+”’;");

}  
return fieldNames;  

}

private static String formatHttpGetParam(Object obj) {
StringBuffer ret = new StringBuffer();
try {
Field[] fields = obj.getClass().getDeclaredFields();
for(int i=0; i<fields.length; i++){
Field f = fields[i];
f.setAccessible(true);

         //属性名=属性值&
         ret.append(f.getName()).append("=").append( f.get(obj) == null ? "" :f.get(obj)).append("&");
     }   
} catch (Exception e) {
	ret = null;
}
 
return ret.toString();

}

/* 根据属性名获取属性值
*
private static Object getFieldValueByName(String fieldName, Object o) {
try {
String firstLetter = fieldName.substring(0, 1).toUpperCase();
String getter = “get” + firstLetter + fieldName.substring(1);
//Method method = o.getClass().getMethod(getter, new Class[] {});
// Object value = method.invoke(o, new Object[] {});
return null;
} catch (Exception e) {

    return null;    
}    

}*/

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值