Class CsvSchema.Builder

  • Enclosing class:
    CsvSchema

    public static class CsvSchema.Builder
    extends java.lang.Object
    Class used for building CsvSchema instances.
    • Field Detail

      • _encodingFeatures

        protected int _encodingFeatures
        Bit-flag for general-purpose on/off features.
        Since:
        2.5
      • _columnSeparator

        protected char _columnSeparator
      • _arrayElementSeparator

        protected java.lang.String _arrayElementSeparator
      • _anyPropertyName

        protected java.lang.String _anyPropertyName
        If "any properties" (properties for 'extra' columns; ones not specified in schema) are enabled, they are mapped to this name: leaving it as null disables use of "any properties" (and they are either ignored, or an exception is thrown, depending on other settings); setting it to a non-null String value will expose all extra properties under one specified name.
        Since:
        2.7
      • _quoteChar

        protected int _quoteChar
      • _escapeChar

        protected int _escapeChar
      • _lineSeparator

        protected char[] _lineSeparator
      • _nullValue

        protected char[] _nullValue
        Since:
        2.5
    • Constructor Detail

      • Builder

        public Builder()
      • Builder

        public Builder​(CsvSchema src)
        "Copy" constructor which creates builder that has settings of given source schema
    • Method Detail

      • addColumn

        public CsvSchema.Builder addColumn​(java.lang.String name)
        NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
      • addColumn

        public CsvSchema.Builder addColumn​(java.lang.String name,
                                           java.util.function.UnaryOperator<CsvSchema.Column> transformer)
        Add column with given name, and with changes to apply (as specified by second argument, transformer). NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
        Parameters:
        name - Name of column to add
        transformer - Changes to apply to column definition
        Since:
        2.18
      • addColumn

        public CsvSchema.Builder addColumn​(java.lang.String name,
                                           CsvSchema.ColumnType type)
        NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
      • addColumn

        public CsvSchema.Builder addColumn​(java.lang.String name,
                                           CsvSchema.ColumnType type,
                                           java.util.function.UnaryOperator<CsvSchema.Column> transformer)
        Add column with given name, and with changes to apply (as specified by second argument, transformer). NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
        Parameters:
        name - Name of column to add
        type - Type of the column to add
        transformer - Changes to apply to column definition
        Since:
        2.18
      • addColumn

        public CsvSchema.Builder addColumn​(CsvSchema.Column c)
        NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
      • addColumns

        public CsvSchema.Builder addColumns​(java.lang.Iterable<CsvSchema.Column> cs)
        NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
        Since:
        2.9
      • addColumns

        public CsvSchema.Builder addColumns​(java.lang.Iterable<java.lang.String> names,
                                            CsvSchema.ColumnType type)
        NOTE: does NOT check for duplicate column names so it is possibly to accidentally add duplicates.
        Since:
        2.9
      • addColumnsFrom

        public CsvSchema.Builder addColumnsFrom​(CsvSchema schema)
        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
      • addArrayColumn

        public CsvSchema.Builder addArrayColumn​(java.lang.String name)
      • addArrayColumn

        public CsvSchema.Builder addArrayColumn​(java.lang.String name,
                                                java.lang.String elementSeparator)
        Since:
        2.7
      • addNumberColumn

        public CsvSchema.Builder addNumberColumn​(java.lang.String name)
      • addBooleanColumn

        public CsvSchema.Builder addBooleanColumn​(java.lang.String name)
      • renameColumn

        public CsvSchema.Builder renameColumn​(int index,
                                              java.lang.String newName)
      • dropLastColumnIfEmpty

        public void dropLastColumnIfEmpty()
        Helper method called to drop the last collected column name if it is empty: called if {link CsvParser.Feature#ALLOW_TRAILING_COMMA} enabled to remove the last entry after being added initially.
        Since:
        2.11.2
      • removeArrayElementSeparator

        public CsvSchema.Builder removeArrayElementSeparator​(int index)
      • setArrayElementSeparator

        public CsvSchema.Builder setArrayElementSeparator​(int index,
                                                          java.lang.String sep)
        Since:
        2.7
      • setAnyPropertyName

        public CsvSchema.Builder setAnyPropertyName​(java.lang.String name)
      • size

        public int size()
      • hasColumn

        public boolean hasColumn​(java.lang.String name)

        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, CsvSchema.column(String) has a hash lookup to use).

        Since:
        2.9
      • setUseHeader

        public CsvSchema.Builder setUseHeader​(boolean b)
        Method for specifying whether Schema should indicate that a header line (first row that contains column names) is to be used for reading and writing or not.
      • setReorderColumns

        public CsvSchema.Builder setReorderColumns​(boolean b)
        Use in combination with setUseHeader. When use header flag is is set, this setting will reorder the columns defined in this schema to match the order set by the header.
        Parameters:
        b - Enable / Disable this setting
        Returns:
        This Builder instance
        Since:
        2.7
      • setStrictHeaders

        public CsvSchema.Builder setStrictHeaders​(boolean b)
        Use in combination with setUseHeader(boolean). When `strict-headers` is set, encoder will ensure the headers are in the order of the schema; if order differs, an exception is thrown.
        Parameters:
        b - Enable / Disable this setting
        Returns:
        This Builder instance
        Since:
        2.7
      • setSkipFirstDataRow

        public CsvSchema.Builder setSkipFirstDataRow​(boolean b)
        Method for specifying whether Schema should indicate that the first line that is not a header (if header handling enabled) should be skipped in its entirety.
      • setAllowComments

        public CsvSchema.Builder setAllowComments​(boolean b)
        Method for specifying whether Schema should indicate that "hash comments" (lines where the first non-whitespace character is '#') are allowed; if so, they will be skipped without processing.
        Since:
        2.5
      • _feature

        protected final void _feature​(int feature,
                                      boolean state)
      • setColumnSeparator

        public CsvSchema.Builder setColumnSeparator​(char c)
        Method for specifying character used to separate column values. Default is comma (',').
      • setArrayElementSeparator

        public CsvSchema.Builder setArrayElementSeparator​(java.lang.String separator)
        Method for specifying character used to separate array element values. Default value is semicolon (";")
        Since:
        2.7
      • disableArrayElementSeparator

        public CsvSchema.Builder disableArrayElementSeparator()
        Since:
        2.7
      • setQuoteChar

        public CsvSchema.Builder setQuoteChar​(char c)
        Method for specifying character used for optional quoting of values. Default is double-quote ('"').
      • setEscapeChar

        public CsvSchema.Builder setEscapeChar​(char c)
        Method for specifying character used for optional escaping of characters in quoted String values. Default is "not used", meaning that no escaping used.
      • disableEscapeChar

        public CsvSchema.Builder disableEscapeChar()
        Method for specifying that no escape character is to be used with CSV documents this schema defines.
      • setLineSeparator

        public CsvSchema.Builder setLineSeparator​(java.lang.String lf)
      • _checkIndex

        protected void _checkIndex​(int index)