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

com.datastax.data.exploration.biz.datatable.column.DataColumn Maven / Gradle / Ivy

package com.datastax.data.exploration.biz.datatable.column;


import com.datastax.data.exploration.biz.datatable.DataType;

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

/**
 * 数据字段,包含字段名字段类型及字段数据,支持数据的查找和写入
 */
public abstract class DataColumn {

    public static String ERROR_TYPE = "type";

    private String columnName;//字段名
    private DataType type;//字段类型
    private List data = new ArrayList<>();
    private List values = new ArrayList<>();
    private Map> errors = new HashMap<>();

    public DataColumn(String columnName, DataType dataType) {
        this.columnName = columnName;
        this.type = dataType;
    }

    abstract E transferValue(String str);
    abstract void flush();

    public E getValue(int i) {
        return this.values.get(i);
    }

    public void setData(int i, String str) {
        E value;
        if (str == null || str.trim().length() == 0) {
            value = null;
        } else {
            value = transferValue(str);
        }

        if (this.data.size() > i) {
            this.data.set(i, str);
            this.values.set(i, value);
        } else {
            this.data.add(str);
            this.values.add(value);
        }
        flush();
    }

    public String getData(int i) {
        return this.data.get(i);
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public DataType getType() {
        return type;
    }

    public void setType(DataType type) {
        this.type = type;
    }

    public int size() {
        return this.data.size();
    }

    /**
     * 输入文本为空的数量
     */
    public int dataNullSize() {
        int i = 0;
        for (String str : this.data) if (str == null || str.trim().isEmpty()) i++;
        return i;
    }

    /**
     * 数值为空的数量
     */
    public int valueNullSize() {
        int i = 0;
        for (E value : this.values) if (value == null) i++;
        return i;
    }

    /**
     * 除setData外,禁止对数据进行修改
     */
    private List getData() {
        return this.data;
    }

    /**
     * 除setData外,禁止对数据进行修改
     */
    private List getValues() {
        return this.values;
    }

    public List getError(String name) {
        return this.errors.get(name);
    }

    void addError(String errorName, String ex) {
        List error = errors.get(errorName);
        if (error == null) {
            error = new ArrayList<>();
            errors.put(errorName, error);
        }
        error.add(ex);
    }

    public List getNotNullValues() {
        return values.stream().filter(v -> v != null).collect(Collectors.toList());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy