Interface BeanInstructions

  • All Known Implementing Classes:
    BeanInstructionsImpl

    public interface BeanInstructions
    These instructions are used to power the BeanReader. Note that the instructions are also used internally if annotations are used.
    Author:
    Robert Bor
    • Method Detail

      • setUseHeader

        BeanInstructions setUseHeader​(boolean useHeader)
        Makes sure that the first readable line is interpreted as the header line. That line will not be read as content. This method is called whenever CsvFile.useHeader() is used. The default value for this setting is true. This call is a facade for RowInstructions.setUseHeader(boolean).
        Parameters:
        useHeader - true if the header is interpreted and used
        Returns:
        convenience for chaining
      • setStartRow

        BeanInstructions setStartRow​(int startRow)
        Sets the start row of the CSV file. If setUseHeader(boolean) == true, this will be the header row and the next ones are all content rows. This method is called whenever CsvFile.startRow() is used. The default value for this setting is 1. This call is a facade for RowInstructions.setStartRow(int).
        Parameters:
        startRow - the first row to start reading, including the header row
        Returns:
        convenience for chaining
      • setEscape

        BeanInstructions setEscape​(char symbol)
        Sets the character that will be interpreted as an escape symbol while within a quoted field. This method is called whenever CsvFile.escape() is used. The default value for this setting is a double quote (") symbol. This call is a facade for RowInstructions.setEscape(char).
        Parameters:
        symbol - the symbol to use for escaping characters within a quoted field
        Returns:
        convenience for chaining
      • setQuote

        BeanInstructions setQuote​(char symbol)
        Sets the character that will be interpreted as a quote symbol, signifying either the start or the end of a quoted field. This method is called whenever CsvFile.quote() is used. The default value for this setting is a double quote (") symbol. This call is a facade for RowInstructions.setQuote(char).
        Parameters:
        symbol - the symbol to use for indicating start/end of a quoted field
        Returns:
        convenience for chaining
      • setQuotingEnabled

        BeanInstructions setQuotingEnabled​(boolean enabled)
        Sets whether or not quotes are written around the field values. If enabled, the character set as the escape symbol will be disabled. If disabled, no quotes are written around the field values and the escape symbol is not escaped. This setting has no effect when reading CSV files, only when writing them.
        Parameters:
        enabled - whether or not to put quotes around fields
        Returns:
        convenience for chaining
      • setSeparator

        BeanInstructions setSeparator​(char symbol)
        Sets the character that will be interpreted as a separator between cells. This method is called whenever CsvFile.separator() is used. The default value for this setting is a semi-colon (;). This call is a facade for RowInstructions.setSeparator(char).
        Parameters:
        symbol - the symbol to use as a separator between cells
        Returns:
        convenience for chaining
      • setComment

        BeanInstructions setComment​(char symbol)
        Sets the character that will be interpreted as a comment field on the first position of a row. This method is called whenever CsvFile.comment() is used. The default value for this setting is a hashtag (#).
        Parameters:
        symbol - the symbol to use as the 0-position comment marker
        Returns:
        convenience for chaining
      • setEndOfLine

        BeanInstructions setEndOfLine​(char[] symbols)
        Sets the characters (plural) that will be interpreted as end-of-line markers (unless within a quoted field). This method is called whenever CsvFile.endOfLine() is used. The default values for this setting are \r and \n. This call is a facade for RowInstructions.setEndOfLine(char[]).
        Parameters:
        symbols - the symbol to interpret as end-of-line markers (unless within a quoted field)
        Returns:
        convenience for chaining
      • skipEmptyLines

        BeanInstructions skipEmptyLines​(boolean skip)
        Determines whether empty lines must be skipped or treated as single-column rows. This method is called whenever CsvFile.skipEmptyLines() is used. The default value for this setting is to skip the empty lines.
        Parameters:
        skip - true to skip empty lines, false to treat as single-column rows
        Returns:
        convenience for chaining
      • skipCommentLines

        BeanInstructions skipCommentLines​(boolean skip)
        Determines whether comment lines must be skipped. This method is called whenever CsvFile.skipCommentLines() is used. The default value for this setting is to skip comment lines. This method exists to guarantee that lines are not accidentally treated as comment lines.
        Parameters:
        skip - true to skip comment lines, identified as starting with a comment marker
        Returns:
        convenience for chaining
      • setStartIndexDynamicColumns

        BeanInstructions setStartIndexDynamicColumns​(int startIndex)
        A file can have a special layout with a dynamic number of columns. If the intention is to duplicate rows for every separate column, this is the method you require. It will remember the start position of the dynamic columns and treat every column after that as dynamic. For every dynamic column a row will be created. If a bean has fields annotated with @CsvHeaderName or @CsvHeaderValue, it will store the values of the header or the cell for that index column in the fields.
        Parameters:
        startIndex - start index of dynamic columns
        Returns:
        convenience for chaining
      • setDate

        BeanInstructions setDate​(String propertyName,
                                 String dateFormat)
        Determines what dateformat to apply to the cell value before storing it as a date. This method is called whenever CsvDate is used. The default for date format is dd-MM-yyyy.
        Parameters:
        propertyName - the name of the property to write the date to
        dateFormat - the date format to apply for parsing the date value
        Returns:
        convenience for chaining
      • setLocalizedNumber

        BeanInstructions setLocalizedNumber​(String propertyName,
                                            Locale locale)
        Determines what Locale to apply to the cell value before converting it to a number. This method is called whenever CsvLocalizedNumber is used. The default for Locale is the Locale of the server.
        Parameters:
        propertyName - the name of the property to write the data to
        locale - the Locale to apply for converting the number
        Returns:
        convenience for chaining
      • setRequired

        BeanInstructions setRequired​(String propertyName,
                                     boolean required)
        Determines if the field is required. If so, the cell may not be empty and a CsvException will be thrown if this occurs. This method is called whenever CsvCell.required() is used. The default for a property is false.
        Parameters:
        propertyName - property for which the requirement applies
        required - whether the cell must be not-null
        Returns:
        convenience for chaining
      • setConverter

        BeanInstructions setConverter​(String propertyName,
                                      Converter converter)
        Sets a custom PropertyEditor for the property. This PropertyEditor is called to convert the text to the type of the property and set it on the bean. This method is called whenever CsvConverter.converter() is used. The default for a property is based on the wonderful set of PropertyEditors that Spring offers, which is all basics and some extras as well.
        Parameters:
        propertyName - property to which the converter must be applied
        converter - PropertyEditor to apply to the property
        Returns:
        convenience for chaining
      • ignoreProperty

        BeanInstructions ignoreProperty​(String propertyName)
        Sets a field to be ignored for purposes of mapping. This method is called whenever CsvIgnore is used. By default none of the fields are ignored unless, custom instructions are used. In this case, all fields are ignored by default.
        Parameters:
        propertyName - property which must be ignored for mapping
        Returns:
        convenience for chaining
      • mapColumnIndexToProperty

        BeanInstructions mapColumnIndexToProperty​(int columnIndex,
                                                  String propertyName)
        Maps a column in the CSV to a specific property. This method is called whenever CsvCell.columnIndex() is used. By default there is NO mapping when custom instructions are used, so you should roll your own. Note that column indexes are 1-based, not 0-based
        Parameters:
        columnIndex - column index for which the property mapping must be applied
        propertyName - property to which the index-based mapping must be applied
        Returns:
        convenience for chaining
      • mapColumnNameToProperty

        BeanInstructions mapColumnNameToProperty​(String columnName,
                                                 String propertyName)
        Maps a column name (which is found in the header) to a specific property. Note that to use this, headers must be enabled. This method is called whenever CsvCell.columnName() is used. By default there is NO mapping when custom instructions are used, so you should roll your own. Also, don't forget to setMapper(Class) to ColumnNameMapper for this to work.
        Parameters:
        columnName - column name for which the property mapping must be applied
        propertyName - property to which the name-based mapping must be applied
        Returns:
        convenience for chaining
      • setHeaderNameToProperty

        BeanInstructions setHeaderNameToProperty​(String propertyName)
        Determines what property will receive the header name in the currently active dynamic column
        Parameters:
        propertyName - property in which the active dynamic header name must be stored
        Returns:
        convenience for chaining
      • setHeaderValueToProperty

        BeanInstructions setHeaderValueToProperty​(String propertyName)
        Determines what property will receive the cell value in the currently active dynamic column
        Parameters:
        propertyName - property in which the active dynamic column value must be stored
        Returns:
        convenience for chaining
      • getBeanClass

        Class getBeanClass()
        Returns the class of the bean on which processing is taking place
        Returns:
        class of the processed bean
      • getProperties

        BeanProperties getProperties()
        Returns the properties of the bean on which processing is taking place
        Returns:
        the properties of the processed bean
      • getRowInstructions

        RowInstructions getRowInstructions()
        Returns the instructions for processing rows
        Returns:
        the row instructions
      • useHeader

        boolean useHeader()
        States whether a header is used
        Returns:
        true if a header is used
      • getStartIndexDynamicColumns

        Column getStartIndexDynamicColumns()
        The first column that counts as a dynamic column
        Returns:
        the first of the dynamic columns
      • getMappingStrategy

        Class<? extends AbstractMapper> getMappingStrategy()
        The mapping strategy to use for processing the bean
        Returns:
        applied mapping strategy
      • logSettings

        void logSettings()
        Logs all the settings