当前位置: 首页>>代码示例>>Java>>正文


Java Table.columnCount方法代码示例

本文整理汇总了Java中tech.tablesaw.api.Table.columnCount方法的典型用法代码示例。如果您正苦于以下问题:Java Table.columnCount方法的具体用法?Java Table.columnCount怎么用?Java Table.columnCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tech.tablesaw.api.Table的用法示例。


在下文中一共展示了Table.columnCount方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import tech.tablesaw.api.Table; //导入方法依赖的package包/类
/**
 * Writes the given table to the given file
 *
 * @throws IOException if the write fails
 */
public static void write(Table table, Writer writer) throws IOException {
    try (CSVWriter csvWriter = new CSVWriter(writer)) {
        String[] header = new String[table.columnCount()];
        for (int c = 0; c < table.columnCount(); c++) {
            header[c] = table.column(c).name();
        }
        csvWriter.writeNext(header, false);
        for (int r = 0; r < table.rowCount(); r++) {
            String[] entries = new String[table.columnCount()];
            for (int c = 0; c < table.columnCount(); c++) {
                table.get(r, c);
                entries[c] = table.get(r, c);
            }
            csvWriter.writeNext(entries, false);
        }
    }
}
 
开发者ID:jtablesaw,项目名称:tablesaw,代码行数:23,代码来源:CsvWriter.java

示例2: crossProduct

import tech.tablesaw.api.Table; //导入方法依赖的package包/类
private void crossProduct(Table destination, Table table1, Table table2) {
  for (int c = 0; c < table1.columnCount() + table2.columnCount(); c++) {
    for (int r = 0; r < table1.rowCount() * table2.rowCount(); r++) {
      if (c < table1.columnCount()) {
        destination.column(c).appendCell(table1.get(r, c));          
      } else {
        destination.column(c).appendCell(table2.get(r, c - table1.columnCount()));
      }
    }    
  }
}
 
开发者ID:jtablesaw,项目名称:tablesaw,代码行数:12,代码来源:DataFrameJoiner.java

示例3: compareTables

import tech.tablesaw.api.Table; //导入方法依赖的package包/类
/**
 * Make sure each row in each table match
 *
 * @param sortedTable the table that was sorted with tablesaw
 * @param compareWith the table that was sorted using some external means e.g. excel. i.e known good data
 */
private void compareTables(Table sortedTable, Table compareWith) {
    assertEquals("both tables have the same number of rows", sortedTable.rowCount(), compareWith.rowCount());
    int maxRows = sortedTable.rowCount();
    int numberOfColumns = sortedTable.columnCount();
    for (int rowIndex = 0; rowIndex < maxRows; rowIndex++) {
        for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
            assertEquals("cells[" + rowIndex + ", " + columnIndex + "]  match",
                    sortedTable.get(rowIndex, columnIndex), compareWith.get(rowIndex, columnIndex));
        }
    }
}
 
开发者ID:jtablesaw,项目名称:tablesaw,代码行数:18,代码来源:SortTest.java

示例4: copyRowsToTable

import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public static void copyRowsToTable(IntArrayList rows, Table oldTable, Table newTable) {

        for (int columnIndex = 0; columnIndex < oldTable.columnCount(); columnIndex++) {
            ColumnType columnType = oldTable.column(columnIndex).type();
            switch (columnType) {
                case FLOAT:
                    copy(rows, (FloatColumn) oldTable.column(columnIndex), (FloatColumn) newTable.column(columnIndex));
                    break;
                case INTEGER:
                    copy(rows, (IntColumn) oldTable.column(columnIndex), (IntColumn) newTable.column(columnIndex));
                    break;
                case SHORT_INT:
                    copy(rows, (ShortColumn) oldTable.column(columnIndex), (ShortColumn) newTable.column(columnIndex));
                    break;
                case LONG_INT:
                    copy(rows, (LongColumn) oldTable.column(columnIndex), (LongColumn) newTable.column(columnIndex));
                    break;
                case CATEGORY:
                    copy(rows, (CategoryColumn) oldTable.column(columnIndex), (CategoryColumn) newTable.column
                            (columnIndex));
                    break;
                case BOOLEAN:
                    copy(rows, (BooleanColumn) oldTable.column(columnIndex), (BooleanColumn) newTable.column
                            (columnIndex));
                    break;
                case DOUBLE:
                    copy(rows, (DoubleColumn) oldTable.column(columnIndex), (DoubleColumn) newTable.column
                            (columnIndex));
                    break;
                case LOCAL_DATE:
                    copy(rows, (DateColumn) oldTable.column(columnIndex), (DateColumn) newTable.column(columnIndex));
                    break;
                case LOCAL_DATE_TIME:
                    copy(rows, (DateTimeColumn) oldTable.column(columnIndex), (DateTimeColumn) newTable.column
                            (columnIndex));
                    break;
                case LOCAL_TIME:
                    copy(rows, (TimeColumn) oldTable.column(columnIndex), (TimeColumn) newTable.column(columnIndex));
                    break;
                default:
                    throw new IllegalStateException("Unhandled column type in case statement");
            }
        }
    }
 
开发者ID:jtablesaw,项目名称:tablesaw,代码行数:45,代码来源:Rows.java

示例5: compareRows

import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public static boolean compareRows(int rowInOriginal, Table original, Table tempTable) {

        boolean result;
        for (int columnIndex = 0; columnIndex < original.columnCount(); columnIndex++) {
            ColumnType columnType = original.column(columnIndex).type();
            switch (columnType) {
                case FLOAT:
                    result = compare(rowInOriginal, (FloatColumn) tempTable.column(columnIndex), (FloatColumn)
                            original.column(columnIndex));
                    if (!result) return false;
                    break;
                case DOUBLE:
                    result = compare(rowInOriginal, (DoubleColumn) tempTable.column(columnIndex), (DoubleColumn)
                            original.column(columnIndex));
                    if (!result) return false;
                    break;
                case INTEGER:
                    result = compare(rowInOriginal, (IntColumn) tempTable.column(columnIndex), (IntColumn) original
                            .column(columnIndex));
                    if (!result) return false;
                    break;
                case SHORT_INT:
                    result = compare(rowInOriginal, (ShortColumn) tempTable.column(columnIndex), (ShortColumn)
                            original.column(columnIndex));
                    if (!result) return false;
                    break;
                case LONG_INT:
                    result = compare(rowInOriginal, (LongColumn) tempTable.column(columnIndex), (LongColumn) original
                            .column(columnIndex));
                    if (!result) return false;
                    break;
                case CATEGORY:
                    result = compare(rowInOriginal, (CategoryColumn) tempTable.column(columnIndex), (CategoryColumn)
                            original.column(columnIndex));
                    if (!result) return false;
                    break;
                case BOOLEAN:
                    result = compare(rowInOriginal, (BooleanColumn) tempTable.column(columnIndex), (BooleanColumn)
                            original.column(columnIndex));
                    if (!result) return false;
                    break;
                case LOCAL_DATE:
                    result = compare(rowInOriginal, (DateColumn) tempTable.column(columnIndex), (DateColumn) original
                            .column(columnIndex));
                    if (!result) return false;
                    break;
                case LOCAL_DATE_TIME:
                    result = compare(rowInOriginal, (DateTimeColumn) tempTable.column(columnIndex), (DateTimeColumn)
                            original.column(columnIndex));
                    if (!result) return false;
                    break;
                case LOCAL_TIME:
                    result = compare(rowInOriginal, (TimeColumn) tempTable.column(columnIndex), (TimeColumn) original
                            .column(columnIndex));
                    if (!result) return false;
                    break;
                default:
                    throw new RuntimeException("Unhandled column type in case statement");
            }
        }
        return true;
    }
 
开发者ID:jtablesaw,项目名称:tablesaw,代码行数:63,代码来源:Rows.java

示例6: read

import tech.tablesaw.api.Table; //导入方法依赖的package包/类
public static Table read(CsvReadOptions options) throws IOException {
    ColumnType[] types = options.columnTypes();
    byte[] bytes = options.reader() != null
        ? CharStreams.toString(options.reader()).getBytes() : null;
    if (types == null) {
      InputStream detectTypesStream = options.reader() != null
          ? new ByteArrayInputStream(bytes)
          : new FileInputStream(options.file());
      types = detectColumnTypes(detectTypesStream, options.header(), options.separator(), options.sample()); 
    }

    // All other read methods end up here, make sure we don't have leading Unicode BOM
    InputStream stream = options.reader() != null
        ? new ByteArrayInputStream(bytes)
        : new FileInputStream(options.file());
    UnicodeBOMInputStream ubis = new UnicodeBOMInputStream(stream);
    ubis.skipBOM();

    Table table;
    CSVParser csvParser = new CSVParserBuilder()
            .withSeparator(options.separator())
            .build();

    try (CSVReader reader = new CSVReaderBuilder(new InputStreamReader(ubis)).withCSVParser(csvParser).build()) {
        String[] nextLine;
        String[] columnNames;
        List<String> headerRow;
        if (options.header()) {
            nextLine = reader.readNext();
            headerRow = Lists.newArrayList(nextLine);
            columnNames = selectColumnNames(headerRow, types);
        } else {
            columnNames = makeColumnNames(types);
            headerRow = Lists.newArrayList(columnNames);
        }

        table = Table.create(options.tableName());
        cleanNames(headerRow);
        for (int x = 0; x < types.length; x++) {
            if (types[x] != SKIP) {
                String columnName = headerRow.get(x);
                if (Strings.isNullOrEmpty(columnName)) {
                    columnName = "Column " + table.columnCount();
                }
                Column newColumn = TypeUtils.newColumn(columnName, types[x]);
                table.addColumn(newColumn);
            }
        }
        int[] columnIndexes = new int[columnNames.length];
        for (int i = 0; i < columnIndexes.length; i++) {
            // get the index in the original table, which includes skipped fields
            columnIndexes[i] = headerRow.indexOf(columnNames[i]);
        }
        // Add the rows
        long rowNumber = options.header() ? 1L : 0L;
        while ((nextLine = reader.readNext()) != null) {
            // for each column that we're including (not skipping)
            int cellIndex = 0;
            for (int columnIndex : columnIndexes) {
                Column column = table.column(cellIndex);
                try {
                    column.appendCell(nextLine[columnIndex]);
                } catch (Exception e) {
                    throw new AddCellToColumnException(e, columnIndex, rowNumber, columnNames, nextLine);
                }
                cellIndex++;
            }
            rowNumber++;
        }
    }
    return table;
}
 
开发者ID:jtablesaw,项目名称:tablesaw,代码行数:73,代码来源:CsvReader.java


注:本文中的tech.tablesaw.api.Table.columnCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。