正确我有3个模型类,其中3个通过SQL从数据库(不同的表)获取数据并将数据保存到arraylists中。 现在我正在尝试将三个数组列表数据输入到表中。 问题是2个数组列表(关闭和关闭2)具有相同数量的数据,1个数组列表只有4个值。我想要的是,如果arraylist中的日期与其他arraylists中的日期不匹配,它将在表中输出为0。
由IF语句完成,该语句检查日期是否相等。
问题是arraylist closing1只有4个值,并且不会让所有其他arraylists循环超过4次。
问题是,我怎么能继续循环通过arraylists关闭和关闭2并从头开始循环遍历arraylist closing1?
try{
Model_Closing[] closing = Model_Closing.QueryWhere();
Model_Closing_DIV[] closing1 = Model_Closing_DIV.QueryWhere();
//Model_Closing_VisUnit[] closing2 = Model_Closing_VisUnit.QueryWhere();
model.setRowCount(0);
for(int i=0; i < closing.length; i++)
if (closing1[i].GetDate().equals(closing[i].GetDate())){
model.insertRow(i,new Object[]{date=closing[i].GetDate(),openingDollarBalance = closingDollarBalance,"NA",fundValue,dollarTransactionAmount,closing[i].GetNAV() * dollarTransactionAmount,visibleUnits,closingDollarBalance,closing[i].GetNAV(),dailyDivRate=closing1[i].GetDiv(),dailyDivDollars = dailyDivRate * accruedUnits,dailyDivRate / closing[i].GetNAV(), accruedDivDollars = accruedUnits * dailyDivRate,accruedUnits = visibleUnits + dailyDivUnits, });
}
else {
dailyDivRate = 0.0;
model.insertRow(i,new Object[]{date=closing[i].GetDate(),openingDollarBalance = closingDollarBalance,"NA",fundValue,dollarTransactionAmount,closing[i].GetNAV() * dollarTransactionAmount,visibleUnits,closingDollarBalance,closing[i].GetNAV(),dailyDivRate,dailyDivDollars = dailyDivRate * accruedUnits,dailyDivRate / closing[i].GetNAV(), accruedDivDollars = accruedUnits * dailyDivRate,accruedUnits = visibleUnits + dailyDivUnits, });
}
if (closingTable == null) {
closingTable = new JTable(model);
add(new JScrollPane(closingTable));
}
else{
closingTable.setModel(model);
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(this,ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
}
答案 0 :(得分:0)
问题是,我怎么能继续通过arraylists循环 关闭和关闭2并开始循环通过arraylist closing1 从开始?
我想你需要的是:
closing1[i%closing1.length].GetDate()== closing[i].GetDate()
答案 1 :(得分:0)
根据对该问题的另一种理解,
Date date1 = (i < closing1.size()) ? closing1[i].GetDate() : zero;
date1 == closing[i].getDate();
其中zero
是“将表格输出为0”