package com.zd.common.core.echarts;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @Author: zhoupan
 * @Date: 2021/09/27/10:49
 * @Description:
 */
public class MapInList extends CommonEchartsData {

    public MapInList(Map<String, Object> o, String key, String v) {
        this.setAxisData(o.get(key).toString());
        this.setDataValue(o.get(v).toString());
    }

    public static List<MapInList> conversion(List<Map<String, Object>> listMap, String key, String v) {

        return Optional.ofNullable(listMap)
                .orElseGet(Collections::emptyList)
                .stream().map(a -> {
                    MapInList mapInList = new MapInList(a, key, v);
                    return mapInList;
                }).collect(Collectors.toList());
    }


}
