public ArrayList < HashMap < String , String > > process ( ArrayList < HashMap < String , String > > soilsData ) { HashMap < String , String > previousSoil ; ArrayList < HashMap < String , String > > aggregatedSoilsData ; HashMap < String , String > aggregatedSoil ; boolean aggregate ; boolean enforceAggregation ; previousSoil = null ; aggregate = true ; enforceAggregation = false ; aggregatedSoilsData = new ArrayList < HashMap < String , String > > ( ) ; ArrayList < HashMap < String , String > > normalizedSoilsData = normalizeSoilLayers ( soilsData ) ; log . debug ( "Formated soil data : " + normalizedSoilsData ) ; int i = 0 ; for ( HashMap < String , String > currentSoil : normalizedSoilsData ) { i ++ ; if ( previousSoil != null ) { if ( aggregatedSoilsData . size ( ) == getMaxSoilLayers ( ) ) { // ok max is reached up to now we enforce aggregation enforceAggregation = true ; } aggregate = decorator . shouldAggregateSoils ( currentSoil , previousSoil ) || enforceAggregation ; if ( aggregate ) { log . debug ( "Aggregating soil layers... " + i + " and " + ( i - 1 ) ) ; log . debug ( "soil " + i + " " + currentSoil ) ; log . debug ( "soil " + ( i - 1 ) + " " + previousSoil ) ; // Compute the new map aggregatedSoil = decorator . computeSoil ( currentSoil , previousSoil ) ; if ( aggregatedSoilsData . contains ( previousSoil ) ) { aggregatedSoilsData . remove ( previousSoil ) ; } // Set as previous soil treated previousSoil = aggregatedSoil ; aggregatedSoilsData . add ( aggregatedSoil ) ; } else { previousSoil = currentSoil ; log . debug ( "Adding soil layer ..." ) ; log . debug ( "soil " + i + " " + currentSoil ) ; aggregatedSoilsData . add ( currentSoil ) ; } } else { previousSoil = currentSoil ; aggregatedSoilsData . add ( currentSoil ) ; } } log . debug ( "Information about soil aggregation" ) ; log . debug ( "Soil layers before : " + soilsData . size ( ) ) ; log . debug ( "Soil layers after : " + aggregatedSoilsData . size ( ) ) ; return aggregatedSoilsData ; }
Process all the soil layers and return a new structure with aggregated data .