package org.kylin.algorithm.strategy.impl;

import org.kylin.algorithm.strategy.SequenceProcessor;
import org.kylin.bean.p5.WCode;
import org.kylin.bean.p5.WCodeReq;
import org.kylin.util.TransferUtil;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Set;

/**
 * 胆增频 ，即输入一组胆abcde与现有p5的前三位比较，如前三位中至少有一个与abcde相符，则P5频度加一
 */
public class SumTailIncreaseFreqProcessor implements SequenceProcessor {

    private List<WCode> wCodes;
    private Set<Integer> sumTailCodes;

    @Override
    public SequenceProcessor init(WCodeReq wCodeReq) {
        if(wCodeReq != null){
            wCodes = wCodeReq.getWCodes();
            sumTailCodes = TransferUtil.toIntegerSet(wCodeReq.getBoldCodeFive());
        }

        return this;
    }

    @Override
    public List<WCode> process() {
        if(!validate()){
            return wCodes;
        }

        for(WCode wCode : wCodes){
            if(sumTailCodes.contains(wCode.getSumTail())){
                wCode.increaseFreq();
            }
        }

        return wCodes;
    }

    @Override
    public boolean validate() {
        if(CollectionUtils.isEmpty(wCodes) || CollectionUtils.isEmpty(sumTailCodes)){
            return false;
        }
        return true;
    }
}

@@ -913,16 +913,112 @@
 Codes)%7B%0A
+            int sumTail = wCode.getCodes().subList(0, 3).stream().reduce(0, Integer::sum) %25 10;%0A
         
@@ -1050,26 +1050,15 @@
 ins(
-wCode.getS
+s
 umTail
-()
 ))%7B%0A

修复p5和增频逻辑