我有一个名为经纪人发票的下面的类,如下所示
经纪人发票类具有一个成员变量,其返回类型为数组

public class BrokerInvoice
{

private BrokerInvoiceLineItem[] lineItemsView;

}


public class BrokerInvoiceLineItem
{
}


现在下面是我要操作的部分,如图所示,即我正在阅读单个选项卡的excel工作表并填充brokerInvoice对象中的所有内容,然后稍后获取BrokerInvoiceLineItem的值

 brokerInvoice = readinginvoiceimpl.findHeaderRowNumber(workbookXls, 0, brokerInvoiceLineItemList, brokerInvoice , brokerIdLong , finalfilteredfilename,dateType );


for (BrokerInvoiceLineItem item : brokerInvoice
                                .getLineItems()) {

                            if (item.getreaddeate() == null) {

                                throw new BOARuntimeException(
                                        "readdeate is not there" );
                            }


现在的问题来了,如果我正在阅读具有多个选项卡的Excel表格,其中每个选项卡数据都与brokerInvoice对象相关联,那么最后我将它们添加到一个名为totalbrokerinvoiceobjects的单独列表中

  //Reading multitabs sheets from excel workbook
            for (int i = 0; i < workbookXls.getNumberOfSheets(); i++) {
            List<BrokerInvoiceLineItem> brokerInvoiceLineItemList = new ArrayList<BrokerInvoiceLineItem>();
            brokerInvoice = readinginvoiceimpl.findHeaderRowNumber(workbookXls, 0, brokerInvoiceLineItemList, brokerInvoice , brokerIdLong , finalfilteredfilename,dateType );
            totalBrokerInvoiceObjects.add(brokerInvoice);
            }


现在所有经纪人发票对象都在名为totalBrokerInvoiceObjects的列表中,现在请告知我如何对每个brokerInvoice对象进行检查,因为我现在必须对名为totalBrokerInvoiceObjects列表中的所有经纪人发票对象进行此检查。

我是否应该先从外部for循环开始,这将首先获取每个代理发票对象,然后在该brokerInvoice对象上检查获取订单项,就像我以前所做的那样

最佳答案

我认为您需要将List实例化移到outer循环之外,并使用addAll将所有内容组合到一个列表中:

List<BrokerInvoiceLineItem> brokerInvoiceLineItemList = new ArrayList<BrokerInvoiceLineItem>();
for (int i = 0; i < workbookXls.getNumberOfSheets(); i++) {
    brokerInvoice = readinginvoiceimpl.findHeaderRowNumber(workbookXls, 0, brokerInvoiceLineItemList, brokerInvoice , brokerIdLong , finalfilteredfilename,dateType );
    for (BrokerInvoiceLineItem item : brokerInvoice.getLineItems()) {
        if (item.getreaddeate() == null) {
            throw new BOARuntimeException("readdeate is not there" );
        }
    }
    totalBrokerInvoiceObjects.addAll(brokerInvoice.getLineItems());
}

07-24 09:16