dimanche 17 mars 2019

Error while filling specific object inside ArrayLists using nested loops and conditional statements

In the following code it is suppose to fill the forecasted unites in the Account only if

  1. the Report date received from the cursor is within the Forecast start and end dates and,

  2. the Item id = to the Item id received from the cursor and

  3. the Account id = to the Account id received from the cursor.

    if (cursor != null && cursor.getCount() > 0) {
        cursor.moveToFirst();
    
        do {
    
            long reportDate = cursor.getLong(cursor.getColumnIndex(ForecastsItemAccountDetailsContract.Columns.Report_Date));
            long itemId = cursor.getLong(cursor.getColumnIndex(ForecastsItemAccountDetailsContract.Columns.Item_ID));
            long accountId = cursor.getLong(cursor.getColumnIndex(ForecastsItemAccountDetailsContract.Columns.Account_ID));
            int forecastedUnits = cursor.getInt(cursor.getColumnIndex(ForecastsItemAccountDetailsContract.Columns.Forecasted_Units));
    
            for (Forecast forecast : mForecasts) {
    
                if ((forecast.getForecast_From() < reportDate) && (forecast.getForecast_To() >= reportDate)) {
    
                    for (Item item : forecast.getItems()) {
    
                        if (item.getItem_ID() == itemId) {
    
                            for (Account account : item.getAccounts()) {
    
                                if (account.getAccount_ID() == accountId) {
    
                                    account.setForecastedUnits(forecastedUnits);
                                }
                            }
                        }
                    }
    
                }
            }
    
        } while (cursor.moveToNext());
    }
    
    

But at the end i find all accounts within all items within all Forecasts having the same forecasted units.

All Are Equal...

What could be the mistake ?

Aucun commentaire:

Enregistrer un commentaire