/** * Method for getting description of column definitions in * developer-readable form */ public String getColumnDesc() { StringBuilder sb = new StringBuilder(100); for (Column col : _columns) { if (sb.length() == 0) { sb.append('['); } else { sb.append(','); } sb.append('"'); sb.append(col.getName()); sb.append('"'); } sb.append(']'); return sb.toString(); }
/** * Method for getting description of column definitions in * developer-readable form */ public String getColumnDesc() { StringBuilder sb = new StringBuilder(100); for (Column col : _columns) { if (sb.length() == 0) { sb.append('['); } else { sb.append(','); } sb.append('"'); sb.append(col.getName()); sb.append('"'); } sb.append(']'); return sb.toString(); }
/** * Method for getting description of column definitions in * developer-readable form */ public String getColumnDesc() { StringBuilder sb = new StringBuilder(100); for (Column col : _columns) { if (sb.length() == 0) { sb.append('['); } else { sb.append(','); } sb.append('"'); sb.append(col.getName()); sb.append('"'); } sb.append(']'); return sb.toString(); }
columnNames.add( column.getName() );
public CsvSchema(Column[] columns, boolean useHeader, boolean skipFirstDataRow, char columnSeparator, char quoteChar, int escapeChar, char[] lineSeparator) { if (columns == null) { columns = NO_COLUMNS; } _columns = columns; _useHeader = useHeader; _skipFirstDataRow = skipFirstDataRow; _columnSeparator = columnSeparator; _quoteChar = quoteChar; _escapeChar = escapeChar; _lineSeparator = lineSeparator; // and then we may need to create a mapping if (_columns.length == 0) { _columnsByName = Collections.emptyMap(); } else { _columnsByName = new HashMap<String,Column>(4 + _columns.length); for (Column c : _columns) { _columnsByName.put(c.getName(), c); } } }
/** * Mutant factory method that will try to combine columns of this schema with those * from `toAppend`, starting with columns of this instance, and ignoring * duplicates (if any) from argument `toAppend`. * All settings aside from column sets are copied from `this` instance. *<p> * As with all `withXxx()` methods this method never modifies `this` but either * returns it unmodified (if no new columns found from `toAppend`), or constructs * a new instance and returns that. * * @since 2.9 */ public CsvSchema withColumnsFrom(CsvSchema toAppend) { int addCount = toAppend.size(); if (addCount == 0) { return this; } Builder b = rebuild(); for (int i = 0; i < addCount; ++i) { Column col = toAppend.column(i); if (column(col.getName()) == null) { b.addColumn(col); } } return b.build(); }
/** * Copy constructor used for creating variants using * <code>sortedBy()</code> methods. */ protected CsvSchema(CsvSchema base, Column[] columns) { _columns = _link(columns); _features = base._features; _columnSeparator = base._columnSeparator; _quoteChar = base._quoteChar; _escapeChar = base._escapeChar; _lineSeparator = base._lineSeparator; _arrayElementSeparator = base._arrayElementSeparator; _nullValue = base._nullValue; _anyPropertyName = base._anyPropertyName; // and then we may need to create a mapping if (_columns.length == 0) { _columnsByName = Collections.emptyMap(); } else { _columnsByName = new HashMap<String,Column>(4 + _columns.length); for (Column c : _columns) { _columnsByName.put(c.getName(), c); } } }
/** * Copy constructor used for creating variants using * <code>sortedBy()</code> methods. */ protected CsvSchema(CsvSchema base, Column[] columns) { _columns = _link(columns); _features = base._features; _columnSeparator = base._columnSeparator; _quoteChar = base._quoteChar; _escapeChar = base._escapeChar; _lineSeparator = base._lineSeparator; _arrayElementSeparator = base._arrayElementSeparator; _nullValue = base._nullValue; _anyPropertyName = base._anyPropertyName; // and then we may need to create a mapping if (_columns.length == 0) { _columnsByName = Collections.emptyMap(); } else { _columnsByName = new HashMap<String,Column>(4 + _columns.length); for (Column c : _columns) { _columnsByName.put(c.getName(), c); } } }
@Override public String toString() { StringBuilder sb = new StringBuilder(150); sb.append("[CsvSchema: ") .append("columns="); boolean first = true; for (Column col : _columns) { if (first) { first = false; sb.append('['); } else { sb.append(','); } sb.append('"'); sb.append(col.getName()); sb.append("\"/"); sb.append(col.getType()); } sb.append(']'); sb.append(']'); return sb.toString(); } }
/** * NOTE: unlike many other add methods, this method DOES check for, and * discard, possible duplicate columns: that is, if this builder already * has a column with same name as column to be added, existing column * is retained and new column ignored. * * @since 2.9 */ public Builder addColumnsFrom(CsvSchema schema) { Builder result = this; for (Column col : schema) { if (!hasColumn(col.getName())) { result = result.addColumn(col); } } return result; }
/** *<p> * NOTE: this method requires linear scan over existing columns * so it may be more efficient to use other types of lookups if * available (for example, {@link CsvSchema#column(String)} has a * hash lookup to use). * * @since 2.9 */ public boolean hasColumn(String name) { for (int i = 0, end = _columns.size(); i < end; ++i) { if (_columns.get(i).getName().equals(name)) { return true; } } return false; }
/** * NOTE: unlike many other add methods, this method DOES check for, and * discard, possible duplicate columns: that is, if this builder already * has a column with same name as column to be added, existing column * is retained and new column ignored. * * @since 2.9 */ public Builder addColumnsFrom(CsvSchema schema) { Builder result = this; for (Column col : schema) { if (!hasColumn(col.getName())) { result = result.addColumn(col); } } return result; }
/** *<p> * NOTE: this method requires linear scan over existing columns * so it may be more efficient to use other types of lookups if * available (for example, {@link CsvSchema#column(String)} has a * hash lookup to use). * * @since 2.9 */ public boolean hasColumn(String name) { for (int i = 0, end = _columns.size(); i < end; ++i) { if (_columns.get(i).getName().equals(name)) { return true; } } return false; }
protected void _handleFirstLine() throws IOException, JsonGenerationException { _handleFirstLine = false; if (_schema.useHeader()) { int count = _schema.size(); if (count == 0) { _reportError("Schema specified that header line is to be written; but contains no column names"); } for (CsvSchema.Column column : _schema) { _writer.writeColumnName(column.getName()); } _writer.endRow(); } } }
protected void _handleFirstLine() throws IOException { _handleFirstLine = false; if (_schema.usesHeader()) { int count = _schema.size(); if (count == 0) { _reportMappingError("Schema specified that header line is to be written; but contains no column names"); } for (CsvSchema.Column column : _schema) { _writer.writeColumnName(column.getName()); } _writer.endRow(); } }
/** * Mutant factory method that will construct a new instance in which columns * are sorted using given {@link Comparator} over column names. * * @since 2.4 */ public CsvSchema sortedBy(Comparator<String> cmp) { TreeMap<String,Column> map = new TreeMap<String,Column>(cmp); for (Column col : _columns) { map.put(col.getName(), col); } return new CsvSchema(this, map.values().toArray(new Column[map.size()])); }
protected void _handleFirstLine() throws IOException { _handleFirstLine = false; if (_schema.usesHeader()) { int count = _schema.size(); if (count == 0) { _reportMappingError("Schema specified that header line is to be written; but contains no column names"); } for (CsvSchema.Column column : _schema) { _writer.writeColumnName(column.getName()); } _writer.endRow(); } }
/** * Mutant factory method that will construct a new instance in which columns * are sorted using given {@link Comparator} over column names. * * @since 2.4 */ public CsvSchema sortedBy(Comparator<String> cmp) { TreeMap<String,Column> map = new TreeMap<String,Column>(cmp); for (Column col : _columns) { map.put(col.getName(), col); } return new CsvSchema(this, map.values().toArray(new Column[map.size()])); }
/** * @since 2.6 */ public String columnName(int index) { return _columns[index].getName(); }
/** * @since 2.6 */ public String columnName(int index) { return _columns[index].getName(); }