package nv.analyzer;

import nv.data.DataStore;

import java.util.ArrayList;
import java.util.List;

/**
 * 分析方法工厂,通过组合分析方法产生分析链,和执行分析链产生最终分析结果. (创建者模式)
 * 正常应该把执行链独立出来一个类,但是要求说要放在一起.
 * 先执行创建,然后附加分析方法,最后执行分析.
 */
public class AnalyzerBuilder {
    private List<AnalyzerMethod> analyzerMethodLinks;
    
    private AnalyzerBuilder() {
    }
    
    
    public static AnalyzerBuilder createAnalyzerLinks() {
        AnalyzerBuilder analyzerBuilder = new AnalyzerBuilder();
        analyzerBuilder.analyzerMethodLinks = new ArrayList<AnalyzerMethod>();
        return analyzerBuilder;
    }
    
    
    public AnalyzerBuilder append(AnalyzerMethod analyzerMethod) {
        analyzerMethodLinks.add(analyzerMethod);
        return this;
    }
    
    public AnalyzerBuilder insert(AnalyzerMethod analyzerMethod, int index) {
        analyzerMethodLinks.add(index, analyzerMethod);
        return this;
    }
    
    /**
     * 构造仓库数据分析者
     *
     * @return
     */
    public StoreDataAnalyzer build() {
        return new StoreDataAnalyzer() {
            @Override
            public DataStore analy(DataStore dataStore) {
                
                DataStore result = null;
                
                for (int i = 0; i < analyzerMethodLinks.size(); i++) {
                    result = analyzerMethodLinks.get(i).execute(result == null ? dataStore : result);
                }
                
                return result;
            }
        };
        
    }
    
}
最近下载更多
我家大宝贝  LV4 2021年6月10日
130duyu  LV7 2020年2月25日
wzzyy12  LV2 2019年12月18日
ml2103  LV5 2019年9月28日
星河远望  LV3 2019年5月9日
liuyishi  LV6 2019年4月6日
ZeroCaiNiao  LV2 2018年12月25日
gygygy51  LV2 2018年3月15日
最代码官方  LV167 2017年10月25日
最近浏览更多
uid0901  LV2 4月2日
1195146710  LV4 1月16日
qq1434100519  LV1 2023年11月1日
2017143155  LV12 2023年6月21日
微信网友_6512020493586432  LV2 2023年6月9日
胡明杨 2023年5月4日
暂无贡献等级
guozhihua12  LV2 2023年4月4日
2716804680  LV9 2023年3月23日
科技家  LV2 2023年3月15日
小小虎牙妹  LV4 2023年3月14日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友