package com.elephant.framework.galaxy.aroad.bigdata;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @program: 路段结果数据分组起点桩号排序排序
 * @description: ${description}
 * @author: dongjili
 * @create: 2019-06-12 15:11
 **/
public class GroupUtils {
    /** 
    * @Description: 分词查询结果的路段数据按照路线编号groupby,起点桩号aorderby 
    * @Param:  list集合路段数据
    * @return:  list集合路段数据
    * @Author: dongjili 
    * @Date: 2019/6/13 0013 
    */ 
    public static  List<Basehighwayalldata> groupByProperty(List<Basehighwayalldata> basehighwayalldataList){
        LinkedHashMap<String, List<Basehighwayalldata>> groupResult = new LinkedHashMap<>();
     //遍历list集合路段数据获取路线编号作为key,数据作为值存储到Map
      for (Basehighwayalldata basehighwayalldata:basehighwayalldataList){
          String key = basehighwayalldata.getLuxianbianhao();
          if (!groupResult.containsKey(key)){
              List<Basehighwayalldata> resultnew = new ArrayList<Basehighwayalldata>();
              resultnew.add(basehighwayalldata);
              groupResult.put(key,resultnew);

          }else {
              groupResult.get(key).add(basehighwayalldata);
          }
      }
//遍历Map集合获取key对应的值，list集合
        List<Basehighwayalldata> basehighwayalldataArrayList = new ArrayList<>();
        for (Map.Entry<String, List<Basehighwayalldata>> entry : groupResult.entrySet()) {
            //System.out.println(entry.getKey()+"========"+entry.getValue());
            List<Basehighwayalldata> entryValue = entry.getValue();
            //slist = list.stream().sorted(Comparator.comparing(Student::getAge)).collect(Collectors.toList());
            //对list集合的值进行排序，排序字段为起点桩号a
            List<Basehighwayalldata> slist = entryValue.stream().sorted(Comparator.comparing(Basehighwayalldata::getQidianzhuanghaoa)).collect(Collectors.toList());
            //排序完成的数据平移到list集合addAll
            basehighwayalldataArrayList.addAll(slist);
        }
       return basehighwayalldataArrayList;
    }
}
