All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datastax.data.exploration.biz.datatable.DataRowCollection Maven / Gradle / Ivy

The newest version!
package com.datastax.data.exploration.biz.datatable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 添加一行数据、根据行号获取行的DataRow
 */
public class DataRowCollection extends ArrayList {

    private DataTable table;

    DataRowCollection(DataTable table) {
        this.table = table;
    }

    public DataRow add(String[] values) throws Exception {
        int count = table.getColumns().size();
        if (count < values.length) {
            throw new Exception("输入数组长度大于此表中的列数。");
        }
        for (int i = 0; i < values.length; i++) {
            if (values[i] != null) {
                this.table.getColumns().getColumn(i).setData(this.size(), values[i]);
            } else {
                this.table.getColumns().getColumn(i).setData(this.size(), null);
            }
        }
        for (int j = values.length; j < count; j++) {
            this.table.getColumns().getColumn(j).setData(this.size(), null);
        }
        DataRow row = new DataRow(table, this.size());
        super.add(row);
        return row;
    }

    public DataRow getRow(int i) throws Exception {
        DataRow datarow;
        try {
            datarow = super.get(i);
        } catch (Exception x) {
            throw new Exception("此索引处不存在列");
        }
        return datarow;
    }

    public Map> aggList(String groupColumnName) {
        Map> map = new HashMap<>();
        for (Object o : super.toArray()) {
            DataRow row = (DataRow)o;
            Object key = row.getValue(groupColumnName);
            if (key != null && row != null) {
                List list = map.get(key);
                if (list == null) {
                    list = new ArrayList<>();
                    map.put(key, list);
                }
                list.add(row);
            }
        }
        return map;
    }

    public List dataDimen3(String axisX, String axisY, String color) {
        List list = new ArrayList<>();
        for (Object o : super.toArray()) {
            DataRow row = (DataRow)o;
            Object[] obj = new Object[3];
            obj[0] = row.getValue(axisX);
            obj[1] = row.getValue(axisY);
            obj[2] = row.getValue(color);
            list.add(obj);
        }
        return list;
    }

    public List dataDimen4(String axisX, String axisY,String axisZ, String color) {
        List list = new ArrayList<>();
        for (Object o : super.toArray()) {
            DataRow row = (DataRow)o;
            Object[] obj = new Object[4];
            obj[0] = row.getValue(axisX);
            obj[1] = row.getValue(axisY);
            obj[2] = row.getValue(axisZ);
            obj[3] = row.getValue(color);
            list.add(obj);
        }
        return list;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy