2016-02-28 48 views
0

工作for循環我有一個低於類名爲經紀人發票,以便如下所示 經紀人發票類有一個成員變量返回類型是陣列的如何使外for循環來對內部在Java

public class BrokerInvoice 
{ 

private BrokerInvoiceLineItem[] lineItemsView; 

} 


public class BrokerInvoiceLineItem 
{ 
} 

現在下面是我在哪裏操縱如圖即我正在閱讀一個單個標籤練成片和填充所有事情在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"); 
          } 

的值的片我我正在讀數據IPLE標籤delimeted Excel表格其中associaoted與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一個seprate列表中添加他們現在請各位指教我怎樣才能perfor每個brokerInvoice對象的檢查,因爲我要檢查這個現在brokerInvoice.getLineItems())對列表中的所有代理髮票對象命名totalBrokerInvoiceObjects

難道我開始外for循環首先將先取每個經紀人發票對象brokerInvoice對象檢查獲取訂單項,因爲我之前使用

+0

你得到什麼錯誤?請花時間改進你的語法。 –

+0

當然,我沒有得到一個錯誤,請告知列表totalbrokerinvoiceobjects裏面包含brokerinvoiceobjects我將如何檢查獲取行項目,因爲我以前做 – sss

回答

2

我認爲你需要移動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()); 
} 
+0

謝謝尼古拉斯,所以這樣我們已經明確添加了所有brokerInvoice對象行項目,但我們將如何跟蹤哪個訂單項屬於哪個經紀商發票對象 – sss

+0

取決於您正在嘗試執行的操作。 –

+0

嗯,我正在嘗試獲取所有與經紀商發票對象對應的行項目,並且如果有任何行項目getrradddeate爲空,我將拋出異常並顯示它是父代理髮票對象信息也 – sss