package roart.component.adviser;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;

import roart.common.pipeline.PipelineConstants;
import roart.component.model.ComponentData;
import roart.iclij.config.Market;
import roart.iclij.config.SimulateInvestConfig;

public class IndicatorMacdHistZeroAdviser extends IndicatorAdviser {

    public IndicatorMacdHistZeroAdviser(Market market, LocalDate investStart, LocalDate investEnd, ComponentData param, SimulateInvestConfig simulateConfig) {
        super(market, investStart, investEnd, param, simulateConfig);
    }

    @Override
    protected int getOffset() {
        return 0;
    }

    @Override
    protected int getOffset2() {
        return 3;
    }

    @Override
    protected String getPipeline() {
        return PipelineConstants.INDICATORMACD;
    }

    @Override
    protected void sort(List<Pair<String, Double>> valueList) {
        if (valueList.isEmpty()) {
            return;
        }
        List<Double> values = valueList.stream().map(Pair::getValue).collect(Collectors.toList());
        int i = 0;
        for (Pair<String, Double> pair : new ArrayList<>(valueList)) {
            Pair aPair = new ImmutablePair(pair.getKey(), Math.abs(pair.getValue()));
            valueList.set(i, aPair);
            i++;
        }
        valueList.sort(Comparator.comparing(Pair::getValue));
        if (indicatorreverse) {
            Collections.reverse(valueList);
        }
    }

}

@@ -1177,107 +1177,8 @@
   %7D%0A
-        List%3CDouble%3E values = valueList.stream().map(Pair::getValue).collect(Collectors.toList());%0A
     
@@ -1188,24 +1188,24 @@
  int i = 0;%0A
+
         for 
@@ -1259,24 +1259,24 @@
 lueList)) %7B%0A
-
             
@@ -1279,16 +1279,32 @@
     Pair
+%3CString, Double%3E
  aPair =

Simplify new adviser for simulate invest action (I220).