private Algorithm configIntermedAlgo(final boolean hasBeenPreviouslySorted) {
        AbstractMultiStepAlgo algorithm = null; 
        Map<StepIOKeys, AlgoIOKeys> stepToAlgoKeysMapping = new StepAlgoKeyMapBuilder()
                                        .add(INTERMEDIATE_DISTINCT_VALUES_HOLDER, DISTINCT_VALUES_HOLDER)
                                        .add(INTERMEDIATE_SERIALIZED_FILE, INTERMEDIATE_OUTPUT_FILE)
                                        .build();
        if(hasBeenPreviouslySorted){
            algorithm = new MultipleSortedFilesInputAlgo("Intermediate Algorithm", stepToAlgoKeysMapping); 
        }else{
            algorithm = new LoopThroughTableInputAlgo("Intermediate Algorithm", stepToAlgoKeysMapping); 
        }
        // initial steps
        // algorithm.addInitStep(new ConfigIntermedColsInitStep());
        algorithm.addInitStep(new ConstrIntermedDataColsInitStep());
        algorithm.addInitStep(new ConstrIntermedGrpColsInitStep());
        // if(!needsProgramaticSorting){
        // algorithm.addInitStep(new ConfigIntermedIOInitStep());
        // }else{
        // algorithm.addInitStep(new
        // ConfigMultiExternalFilesInputForIntermReportInitStep());
        // }
        algorithm.addInitStep(new ConfigIntermedReportOutputInitStep());
        algorithm.addInitStep(stepInput -> {
            ((IntermediateCrosstabOutput) stepInput.getContextParam(INTERMEDIATE_CROSSTAB_OUTPUT)).open();
            return NO_RESULT;
        });
        // TODO: only when totals add the step below
        algorithm.addInitStep(new IntermedReportExtractTotalsDataInitStep());
        // only for debug
        // algorithm.addInitStep(new ColumnHeaderOutputInitStep("Intermediate report"));
        // main steps
        algorithm.addMainStep(new DistinctValuesDetectorStep());
        algorithm.addMainStep(new IntermedGroupLevelDetectorStep());
        // only for debug
        // if( getShowTotals() || getShowGrandTotal()){
        // algorithm.addMainStep(new FlatReportTotalsOutputStep());
        // }
        algorithm.addMainStep(new IntermedRowMangerStep());
        if (getShowTotals() || getShowGrandTotal()) {
            algorithm.addMainStep(new IntermedTotalsCalculatorStep());
        }
        // only for debug
        // algorithm.addMainStep(new DataRowsOutputStep());
        // if( intermediateGroupCols.size() > 0){
        algorithm.addMainStep(new IntermedPreviousRowManagerStep());
        // }
        algorithm.addExitStep(stepInput -> {
                ((IntermediateCrosstabOutput) stepInput.getContextParam(INTERMEDIATE_CROSSTAB_OUTPUT)).close();
                return NO_RESULT;
        });
        algorithm.addExitStep(new IntermedSetResultsExitStep());
        return algorithm;
    }
private Algorithm configIntermedAlgo(final boolean hasBeenPreviouslySorted) {
        AbstractMultiStepAlgo algorithm = null; 
        Map<StepIOKeys, AlgoIOKeys> stepToAlgoKeysMapping = new StepAlgoKeyMapBuilder()
                                        .add(INTERMEDIATE_DISTINCT_VALUES_HOLDER, DISTINCT_VALUES_HOLDER)
                                        .add(INTERMEDIATE_SERIALIZED_FILE, INTERMEDIATE_OUTPUT_FILE)
                                        .build();
        if(hasBeenPreviouslySorted){
            algorithm = new MultipleSortedFilesInputAlgo("Intermediate Algorithm", stepToAlgoKeysMapping); 
        }else{
            algorithm = new LoopThroughTableInputAlgo("Intermediate Algorithm", stepToAlgoKeysMapping); 
        }
       
       
        algorithm.addInitStep(new ConstrIntermedDataColsInitStep());
        algorithm.addInitStep(new ConstrIntermedGrpColsInitStep());
       
       
       
       
       
       
        algorithm.addInitStep(new ConfigIntermedReportOutputInitStep());
        algorithm.addInitStep(stepInput -> {
            ((IntermediateCrosstabOutput) stepInput.getContextParam(INTERMEDIATE_CROSSTAB_OUTPUT)).open();
            return NO_RESULT;
        });
       
        algorithm.addInitStep(new IntermedReportExtractTotalsDataInitStep());
       
       
       
        algorithm.addMainStep(new DistinctValuesDetectorStep());
        algorithm.addMainStep(new IntermedGroupLevelDetectorStep());
       
       
       
       
        algorithm.addMainStep(new IntermedRowMangerStep());
        if (getShowTotals() || getShowGrandTotal()) {
            algorithm.addMainStep(new IntermedTotalsCalculatorStep());
        }
       
       
       
        algorithm.addMainStep(new IntermedPreviousRowManagerStep());
       
        algorithm.addExitStep(stepInput -> {
                ((IntermediateCrosstabOutput) stepInput.getContextParam(INTERMEDIATE_CROSSTAB_OUTPUT)).close();
                return NO_RESULT;
        });
        algorithm.addExitStep(new IntermedSetResultsExitStep());
        return algorithm;
    }
private algorithm configintermedalgo(final boolean hasbeenpreviouslysorted) { abstractmultistepalgo algorithm = null; map<stepiokeys, algoiokeys> steptoalgokeysmapping = new stepalgokeymapbuilder() .add(intermediate_distinct_values_holder, distinct_values_holder) .add(intermediate_serialized_file, intermediate_output_file) .build(); if(hasbeenpreviouslysorted){ algorithm = new multiplesortedfilesinputalgo("intermediate algorithm", steptoalgokeysmapping); }else{ algorithm = new loopthroughtableinputalgo("intermediate algorithm", steptoalgokeysmapping); } algorithm.addinitstep(new constrintermeddatacolsinitstep()); algorithm.addinitstep(new constrintermedgrpcolsinitstep()); algorithm.addinitstep(new configintermedreportoutputinitstep()); algorithm.addinitstep(stepinput -> { ((intermediatecrosstaboutput) stepinput.getcontextparam(intermediate_crosstab_output)).open(); return no_result; }); algorithm.addinitstep(new intermedreportextracttotalsdatainitstep()); algorithm.addmainstep(new distinctvaluesdetectorstep()); algorithm.addmainstep(new intermedgroupleveldetectorstep()); algorithm.addmainstep(new intermedrowmangerstep()); if (getshowtotals() || getshowgrandtotal()) { algorithm.addmainstep(new intermedtotalscalculatorstep()); } algorithm.addmainstep(new intermedpreviousrowmanagerstep()); algorithm.addexitstep(stepinput -> { ((intermediatecrosstaboutput) stepinput.getcontextparam(intermediate_crosstab_output)).close(); return no_result; }); algorithm.addexitstep(new intermedsetresultsexitstep()); return algorithm; }