Package de.xima.fc.logic.text.csv
Class CsvFormat.Builder
- java.lang.Object
-
- de.xima.fc.logic.text.csv.CsvFormat.Builder
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CsvFormat.Builder
allowDoubleQuoteEscape(boolean allowDoubleQuoteEscape)
Whether to allow double quote escape.CsvFormat
build()
Builds theCsvFormat
instance.CsvFormat.Builder
cellFilter(Predicate<String> cellFilter)
Sets the cell filter that is applied to each cell.CsvFormat.Builder
cellNormalizer(UnaryOperator<String> cellNormalizer)
Sets the cell normalizer that is applied to each cell.CsvFormat.Builder
delimiter(int delimiter)
Sets the character used to delimit cells.CsvFormat.Builder
delimiter(String delimiter)
Sets the character used to delimit cells.CsvFormat.Builder
escape(int escape)
Sets the character used to escape special characters in a cell.CsvFormat.Builder
escape(String escape)
Sets the character used to escape special characters in a cell.CsvFormat.Builder
ignoreBlankCells(boolean filterBlankCells)
Sets up thecellFilter
to filter out blank cells.CsvFormat.Builder
ignoreEmptyCells(boolean filterEmptyCells)
Sets up thecellFilter
to filter out empty cells.CsvFormat.Builder
newlines(String... newlines)
Sets the characters that are treated as newlines.CsvFormat.Builder
newlines(Collection<String> newlines)
Sets the characters that are treated as newlines.CsvFormat.Builder
quote(int quote)
Sets thequoteOpen
andquoteClose
characters to the same value.CsvFormat.Builder
quote(String quote)
Sets thequoteOpen
andquoteClose
characters to the same value.CsvFormat.Builder
quoteClose(int quoteClose)
Sets the character used to end a quoted cell.CsvFormat.Builder
quoteClose(String quoteClose)
Sets the character used to end a quoted cell.CsvFormat.Builder
quoteOpen(int quoteOpen)
Sets the character used to start a quoted cell.CsvFormat.Builder
quoteOpen(String quoteOpen)
Sets the character used to start a quoted cell.CsvFormat.Builder
rowFilter(Predicate<List<String>> rowFilter)
Sets the row filter that is applied to each row after it was split into cells.CsvFormat.Builder
rowMutator(Consumer<List<String>> rowMutator)
Sets the row normalizer that is applied to each row after it was split into cells.CsvFormat.Builder
rowNormalizer(UnaryOperator<List<String>> rowNormalizer)
Sets the row normalizer that is applied to each row after it was split into cells.CsvFormat.Builder
treatLineBreaksAsDelimiter(boolean treatLineBreaksAsDelimiter)
When set totrue
, line breaks will be treated as cell delimiters.CsvFormat.Builder
trimCells(boolean trimCells)
Sets up thecellNormalizer
to trim cells, i.e.
-
-
-
Method Detail
-
allowDoubleQuoteEscape
public CsvFormat.Builder allowDoubleQuoteEscape(boolean allowDoubleQuoteEscape)
Whether to allow double quote escape. If set totrue
, a quote character can be escaped by repeating it.- Parameters:
allowDoubleQuoteEscape
- Whether to allow double quote escape.- Returns:
- This builder for chaining method calls.
-
build
public CsvFormat build()
Builds theCsvFormat
instance. Modifying the builder after calling this method has no effect on the returned instance.- Returns:
- The
CsvFormat
instance.
-
cellFilter
public CsvFormat.Builder cellFilter(Predicate<String> cellFilter)
Sets the cell filter that is applied to each cell. The filter is applied after the cell normalizer and may remove cells from the result.- Parameters:
cellFilter
- The cell filter.- Returns:
- This builder for chaining method calls.
-
cellNormalizer
public CsvFormat.Builder cellNormalizer(UnaryOperator<String> cellNormalizer)
Sets the cell normalizer that is applied to each cell. The normalizer is applied before the cell filter and may transform the cell into a different cell.- Parameters:
cellNormalizer
- The cell normalizer.- Returns:
- This builder for chaining method calls.
-
delimiter
public CsvFormat.Builder delimiter(int delimiter)
Sets the character used to delimit cells.- Parameters:
delimiter
- The delimiter character.- Returns:
- This builder for chaining method calls.
-
delimiter
public CsvFormat.Builder delimiter(String delimiter)
Sets the character used to delimit cells.- Parameters:
delimiter
- The delimiter character.- Returns:
- This builder for chaining method calls.
-
escape
public CsvFormat.Builder escape(int escape)
Sets the character used to escape special characters in a cell.- Parameters:
escape
- The escape character.- Returns:
- This builder for chaining method calls.
-
escape
public CsvFormat.Builder escape(String escape)
Sets the character used to escape special characters in a cell.- Parameters:
escape
- The escape character.- Returns:
- This builder for chaining method calls.
-
ignoreBlankCells
public CsvFormat.Builder ignoreBlankCells(boolean filterBlankCells)
Sets up thecellFilter
to filter out blank cells.- Parameters:
filterBlankCells
- Iftrue
, blank cells will be filtered out.- Returns:
- This builder for chaining method calls.
-
ignoreEmptyCells
public CsvFormat.Builder ignoreEmptyCells(boolean filterEmptyCells)
Sets up thecellFilter
to filter out empty cells.- Parameters:
filterEmptyCells
- Iftrue
, empty cells will be filtered out.- Returns:
- This builder for chaining method calls.
-
newlines
public CsvFormat.Builder newlines(Collection<String> newlines)
Sets the characters that are treated as newlines.- Parameters:
newlines
- The newline characters.- Returns:
- This builder for chaining method calls.
-
newlines
public CsvFormat.Builder newlines(String... newlines)
Sets the characters that are treated as newlines.- Parameters:
newlines
- The newline characters.- Returns:
- This builder for chaining method calls.
-
quote
public CsvFormat.Builder quote(String quote)
Sets thequoteOpen
andquoteClose
characters to the same value.- Parameters:
quote
- The quote character.- Returns:
- This builder for chaining method calls.
-
quote
public CsvFormat.Builder quote(int quote)
Sets thequoteOpen
andquoteClose
characters to the same value.- Parameters:
quote
- The quote character.- Returns:
- This builder for chaining method calls.
-
quoteClose
public CsvFormat.Builder quoteClose(int quoteClose)
Sets the character used to end a quoted cell.- Parameters:
quoteClose
- The quote character.- Returns:
- This builder for chaining method calls.
-
quoteClose
public CsvFormat.Builder quoteClose(String quoteClose)
Sets the character used to end a quoted cell.- Parameters:
quoteClose
- The quote character.- Returns:
- This builder for chaining method calls.
-
quoteOpen
public CsvFormat.Builder quoteOpen(int quoteOpen)
Sets the character used to start a quoted cell.- Parameters:
quoteOpen
- The quote character.- Returns:
- This builder for chaining method calls.
-
quoteOpen
public CsvFormat.Builder quoteOpen(String quoteOpen)
Sets the character used to start a quoted cell.- Parameters:
quoteOpen
- The quote character.- Returns:
- This builder for chaining method calls.
-
rowFilter
public CsvFormat.Builder rowFilter(Predicate<List<String>> rowFilter)
Sets the row filter that is applied to each row after it was split into cells. The filter is applied after the cell normalizer and may remove rows from the result.- Parameters:
rowFilter
- The row filter.- Returns:
- This builder for chaining method calls.
-
rowMutator
public CsvFormat.Builder rowMutator(Consumer<List<String>> rowMutator)
Sets the row normalizer that is applied to each row after it was split into cells. The normalizer is applied before the row filter and may transform the row into a different row.- Parameters:
rowMutator
- The row normalizer.- Returns:
- This builder for chaining method calls.
-
rowNormalizer
public CsvFormat.Builder rowNormalizer(UnaryOperator<List<String>> rowNormalizer)
Sets the row normalizer that is applied to each row after it was split into cells. The normalizer is applied before the row filter and may transform the row into a different row.- Parameters:
rowNormalizer
- The row normalizer.- Returns:
- This builder for chaining method calls.
-
treatLineBreaksAsDelimiter
public CsvFormat.Builder treatLineBreaksAsDelimiter(boolean treatLineBreaksAsDelimiter)
When set totrue
, line breaks will be treated as cell delimiters. Useful when splitting a single row of characters separated values. Not recommended for splitting multiple rows (as it will result in a single row with all cells).- Parameters:
treatLineBreaksAsDelimiter
- Whether to treat line breaks as delimiters.- Returns:
- This builder for chaining method calls.
-
trimCells
public CsvFormat.Builder trimCells(boolean trimCells)
Sets up thecellNormalizer
to trim cells, i.e. remove leading and trailing whitespace.- Parameters:
trimCells
- Iftrue
, cells will be trimmed.- Returns:
- This builder for chaining method calls.
-
-