private String [ ] getExpectedRow ( TableIterator < String [ ] > tableRowIterator , DateTime expectedDT ) throws IOException { while ( tableRowIterator . hasNext ( ) ) { String [ ] row = tableRowIterator . next ( ) ; DateTime currentTimestamp = formatter . parseDateTime ( row [ 1 ] ) ; if ( currentTimestamp . equals ( expectedDT ) ) { if ( pNum == 1 ) { return row ; } else { String [ ] [ ] allRows = new String [ pNum ] [ ] ; allRows [ 0 ] = row ; int rowNum = 1 ; for ( int i = 1 ; i < pNum ; i ++ ) { if ( tableRowIterator . hasNext ( ) ) { String [ ] nextRow = tableRowIterator . next ( ) ; allRows [ i ] = nextRow ; rowNum ++ ; } } // now aggregate String [ ] aggregatedRow = new String [ row . length ] ; // date is the one of the first instant aggregatedRow [ 0 ] = allRows [ 0 ] [ 0 ] ; aggregatedRow [ 1 ] = allRows [ 0 ] [ 1 ] ; for ( int col = 2 ; col < allRows [ 0 ] . length ; col ++ ) { boolean hasOne = false ; switch ( pAggregation ) { case 0 : double sum = 0 ; for ( int j = 0 ; j < rowNum ; j ++ ) { String valueStr = allRows [ j ] [ col ] ; if ( ! valueStr . equals ( fileNovalue ) ) { double value = Double . parseDouble ( valueStr ) ; sum = sum + value ; hasOne = true ; } } if ( ! hasOne ) { sum = doubleNovalue ; } aggregatedRow [ col ] = String . valueOf ( sum ) ; break ; case 1 : double avg = 0 ; for ( int j = 0 ; j < rowNum ; j ++ ) { String valueStr = allRows [ j ] [ col ] ; if ( ! valueStr . equals ( fileNovalue ) ) { double value = Double . parseDouble ( valueStr ) ; avg = avg + value ; hasOne = true ; } } if ( ! hasOne ) { avg = doubleNovalue ; } else { avg = avg / pNum ; } aggregatedRow [ col ] = String . valueOf ( avg ) ; break ; default : break ; } } return aggregatedRow ; } } else if ( currentTimestamp . isBefore ( expectedDT ) ) { // browse until the instant is found continue ; } else if ( currentTimestamp . isAfter ( expectedDT ) ) { /* * lost the moment, for now throw exception. * Could be enhanced in future. */ String message = "The data are not aligned with the simulation interval (" + currentTimestamp + "/" + expectedDT + "). Check your data file: " + file ; throw new IOException ( message ) ; } } return null ; }
Get the needed datarow from the table .