use of tech.tablesaw.api.ColumnType.SKIP in project symja_android_library by axkr.
the class FileReader method parseRows.
protected Table parseRows(ReadOptions options, boolean headerOnly, Reader reader, ReadOptions.ColumnTypeReadOptions columnTypeReadOptions, AbstractParser<?> parser, int sampleSize) {
parser.beginParsing(reader);
Table table = Table.create(options.tableName());
List<String> headerRow = Lists.newArrayList(getColumnNames(options, columnTypeReadOptions, parser));
@SuppressWarnings({ "UnstableApiUsage", "OptionalGetWithoutIsPresent" }) ColumnType[] types = Streams.mapWithIndex(headerRow.stream(), (columnName, idx) -> columnTypeReadOptions.columnType((int) idx, columnName)).filter(Optional::isPresent).map(Optional::get).toArray(ColumnType[]::new);
for (int x = 0; x < types.length; x++) {
if (types[x] != SKIP) {
String columnName = cleanName(headerRow.get(x));
if (Strings.isNullOrEmpty(columnName)) {
columnName = "Column " + table.columnCount();
}
Column<?> newColumn = types[x].create(columnName);
table.addColumns(newColumn);
}
}
if (!headerOnly) {
String[] columnNames = selectColumnNames(headerRow, types);
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]);
}
addRows(options, types, parser, table, columnIndexes, sampleSize);
}
return table;
}
Aggregations