0
我有3個獨立的對象,如GSMTable,SMSTable和GPRSTable。 這些包括2個字段srDate和numberOfSR。 現在我需要讓他們到一個三維數組對象,因爲我需要回到它爲我jqPlot線圖 這是我的要求:創建3D數組對象
[
[gsmTable.srDate][gsmTable.noOfSR],
[smsTable.srDate][smsTable.noOfSR],
[gprsTable.srDate][gprsTable.noOfSR]
]
我寫我自己的代碼像下面,但我不能完成它。
@RequestMapping(value = "/allGridView", method = RequestMethod.GET)
public @ResponseBody
Object[] showLineChart(Map<String, Object> map, HttpServletRequest request,
HttpServletResponse response) {
List<GSMTable> gsmList = contactService.fin();
List<Date>gsmDateList=new ArrayList<Date>();
List<Integer>gsmCount=new ArrayList<Integer>();
Object[] gsmArray=new Object[2];
for (Iterator iterator =gsmList.iterator();iterator.hasNext();) {
GSMTable gsmTable=(GSMTable)iterator.next();
gsmDateList.add(gsmTable.getSRDate());
gsmCount.add(gsmTable.getNumberOfSR());
}
gsmArray[0]=gsmDateList.toArray(new Date[gsmDateList.size()]);
gsmArray[1]=gsmCount.toArray(new Integer[gsmCount.size()]);
//=====================================================================================
List<SMSTable> smsList = contactService.sms();
List<Date>smsDateList=new ArrayList<Date>();
List<Integer>smsCount=new ArrayList<Integer>();
Object[] smsArray=new Object[2];
for (Iterator iterator =smsList.iterator();iterator.hasNext();) {
SMSTable smsTable=(SMSTable)iterator.next();
smsDateList.add(smsTable.getSRDate());
smsCount.add(smsTable.getNumberOfSR());
}
smsArray[0]=smsDateList.toArray(new Date[smsDateList.size()]);
smsArray[1]=smsCount.toArray(new Integer[smsCount.size()]);
//=====================================================================================
List<GPRSTable> gprsList = contactService.gprs();
List<Date>gprsDateList=new ArrayList<Date>();
List<Integer>gprsCount=new ArrayList<Integer>();
Object[] gprsArray=new Object[2];
for (Iterator iterator =gprsList.iterator();iterator.hasNext();) {
GPRSTable gprsTable=(GPRSTable)iterator.next();
gprsDateList.add(gprsTable.getSRDate());
gprsCount.add(gprsTable.getNumberOfSR());
}
gprsArray[0]=gprsDateList.toArray(new Date[gprsDateList.size()]);
gprsArray[1]=gprsCount.toArray(new Integer[gprsCount.size()]);
Object[][][] finalArray;
//after that how to complete it ? ? ?
//need to return finalArray as 3D Object Array
return finalArray;
}
gsmArray:
[[2012-11-05,05],[2012-11-06,08],[2012-11-07,10],[2012-11-08,14],[2012-11-08,09]]
smsArray:
[[2012-11-05,02],[2012-11-06,03],[2012-11-07,04],[2012-11-08,04],[2012-11-08,03]]
gprsArray:
[[2012-11-05,04],[2012-11-06,07],[2012-11-07,08],[2012-11-08,04],[2012-11-08,07]]
我需要合併gsmArray,smsArray和gprsArray作爲3D陣列 然後我期待陣列應該是:
[[2012-11-05,05],[2012-11-06,08],[2012-11-07,10],[2012-11-08,14],[2012-11-08,09],[2012-11-05,02],[2012-11-06,03],[2012-11-07,04],[2012-11-08,04],[2012-11-08,03],[2012-11-05,04],[2012-11-06,07],[2012-11-07,08],[2012-11-08,04],[2012-11-08,07]]
而是這一切混亂的,使用一個包含HashMap。 –
Object [] [] [] [] finalArray; ?或Object [] [] [] finalArray; – dreamcrash
dreamcrash - >修正後它應該是Object [] [] [] finalArray –