我有一个 bean 列表,我正在检查该列表中是否至少有 2 个带有返回“VALUEA”和“VALUEB”的 getter 的 bean。这样我就可以为他们两个构建一个名为“VALUEC TOTAL”的“总”bean。我还在最后做了一个“总计”的豆排。
我的问题只是“VALUEC TOTAL”。我需要在原始列表中的“VALUEB”之后将该 bean 添加到列表中,而不是我在最后的操作方式。
我可以确认摘要不为空。
summary = new ArrayList<WorkoutPlanBean>();
beans = dao.getAppropriationSummaryBySor(criteria, summary);
//Here we are setting up lists to be used to be added to the bottom of "Rollup" as "Totals"
List<WorkoutPlanBean> valuecList = new ArrayList<WorkoutPlanBean>();
List<WorkoutPlanBean> sumList = new ArrayList<WorkoutPlanBean>();
for (WorkoutPlanBean b: summary)
{
//We need 2 beans...one with VALUEA and one with VALUEB
if( b.getSor().getShortName().equals("VALUEA") || b.getSor().getShortName().equals("VALUEB"))
{
valuecList.add(b);
}
sumList.add(b);
}
// Create VALUEC totals bean.
if (valuecList.size() > 1 )
{
WorkoutPlanBean valuecTotals = new WorkoutPlanBean();
valuecTotals.setSor(VALUEC_TOTALS_SOR);
for (WorkoutPlanBean bean : valuecList)
{
valuecTotals.setQuantity(Overview.totalsIntegerAdd(valuecTotals.getQuantity(),
bean.getQuantity()));
valuecTotals.setHours(Overview.totalsDoubleAdd(valuecTotals.getHours(),
bean.getHours()));
valuecTotals.setValue(Overview.totalsBigDecimalAdd(valuecTotals.getValue(),
bean.getValue()));
}
summary.add(valuecTotals);
}
// Create Totals bean.
if (sumList.size() > 1 )
{
WorkoutPlanBean globalTotals = new WorkoutPlanBean();
globalTotals.setSor(GRAND_TOTALS_SOR);
for (WorkoutPlanBean bean : sumList)
{
globalTotals.setQuantity(Overview.totalsIntegerAdd(globalTotals.getQuantity(),
bean.getQuantity()));
globalTotals.setHours(Overview.totalsDoubleAdd(globalTotals.getHours(),
bean.getHours()));
globalTotals.setValue(Overview.totalsBigDecimalAdd(globalTotals.getValue(),
bean.getValue()));
}
summary.add(globalTotals);
}
request.setAttribute("summary", summary);