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

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

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

import com.datastax.data.exploration.biz.datatable.column.*;

import java.util.ArrayList;

/**
 * 列的集合类,支持在集合中添加、移除、查询列
 */
public class DataColumnCollection extends ArrayList {

    public boolean add(DataColumn column) {
        return super.add(column);
    }

    public boolean add(String columnName, DataType type) {
        DataColumn column;
        switch (type) {
            case BINOMIAL:
                column = new BinomialColumn(columnName);
                break;
            case POLYNOMIAL:
                column = new PolynomialColumn(columnName);
                break;
            case DECIMAL:
                column = new DecimalColumn(columnName);
                break;
            case INT:
                column = new IntegerColumn(columnName);
                break;
            case DATE_TIME:
                column = new DateTimeColumn(columnName);
                break;
            case DATE:
                column = new DateColumn(columnName);
                break;
            case TIME:
                column = new TimeColumn(columnName);
                break;
            default:
                column = new TextColumn(columnName);
                break;
        }
        return add(column);
    }

    public DataColumn getColumn(String name) {
        if (name == null) {
            return null;
        }
        for (Object c : super.toArray()) {
            DataColumn column = (DataColumn) c;
            if (column.getColumnName().equals(name))
                return column;
        }
        return null;
    }

    /**
     * 如果当前集合存在明细为value的明细则返回true
     */
    public boolean contains(String columnName) {
        for (Object c : super.toArray()) {
            DataColumn column = (DataColumn) c;
            if (column.getColumnName().equals(columnName))
                return true;
        }
        return false;
    }


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

    /**
     * 移除
     */
    private void remove(DataColumn value) {
        super.remove(value);
    }

    public void remove(String columnName) {
        for (Object c : super.toArray()) {
            DataColumn column = (DataColumn) c;
            if (column.getColumnName().equals(columnName)) {
                remove(column);
                break;
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy