shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.walker.di.univocity.util;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
public class BatchLoadUtils {
 
    /**
     * 把CSV加载到的批量列数据,转换成行数据集合,原始格式如下:
     * <pre>
     *     Map中: key = 列名称, value = 该列包含所有行的值;
     *     user_name --> ['shikeying', 'mike', 'zhangsan', null]
     * </pre>
     * @param columnsByName
     * @param fieldNames
     * @param dataSize
     * @return List中是行,数组包含一行的所有列值。
     * @date 2023-02-01
     */
    public static final List<Object[]> translateTo(Map<String, List<String>> columnsByName
            , String[] fieldNames, int dataSize){
        List<Object[]> resultList = new ArrayList<>(256);
        int columnSize = fieldNames.length;
        for(int i=0; i<dataSize; i++){
            String columnValue = null;
            Object[] data = new Object[columnSize];
            for(int j=0; j< columnSize; j++){
                columnValue = columnsByName.get(fieldNames[j]).get(i);
                data[j] = columnValue;
            }
            resultList.add(data);
        }
        return resultList;
    }
//    public static final List<Object[]> translateTo(Map<String, List<String>> columnsByName
//            , List<String> fieldNames, int dataSize){
//        List<Object[]> resultList = new ArrayList<>(256);
//        int columnSize = fieldNames.size();
//        for(int i=0; i<dataSize; i++){
//            String columnValue = null;
//            Object[] data = new Object[columnSize];
//            for(int j=0; j< fieldNames.size(); j++){
//                columnValue = columnsByName.get(fieldNames.get(j)).get(i);
//                data[j] = columnValue;
//            }
//            resultList.add(data);
//        }
//        return resultList;
//    }
}