Package org.refcodes.textual
Class CsvBuilderImpl
- java.lang.Object
-
- org.refcodes.textual.CsvBuilderImpl
-
- All Implemented Interfaces:
CsvBuilder
public class CsvBuilderImpl extends java.lang.Object implements CsvBuilder
The Class CsvBuilderImpl.- Author:
- steiner
-
-
Constructor Summary
Constructors Constructor Description CsvBuilderImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static java.util.List<java.lang.String>
fromSeparatedValues(java.lang.String aSeparatedValues)
Takes theString
and creates aList
withString
instances containing the elements as identified from theString
by splitting theString
at the delimiter positions and adding those chunks to theList
with the accordingDelimiter.CSV
delimiter..protected static java.util.List<java.lang.String>
fromSeparatedValues(java.lang.String aSeparatedValues, char aDelimiter)
Takes theString
and creates aList
withString
instances containing the elements as identified from theString
by splitting theString
at the delimiter positions and adding those chunks to theList
.protected static java.util.List<java.lang.String>
fromSeparatedValues(java.lang.String aRecord, char aDelimiter, CsvEscapeMode aCsvEscapeMode)
From separated values.protected static java.util.List<java.lang.String>
fromSplitValues(java.lang.String aSplitValues)
Takes theString
and creates aList
withString
instances containing the elements as identified from theString
by splitting theString
at the delimiter positions and adding those chunks to theList
with the accordingDelimiter.CSV
delimiter..protected static java.util.List<java.lang.String>
fromSplitValues(java.lang.String aSplitValues, char aDelimiter)
Takes theString
and creates aList
withString
instances containing the elements as identified from theString
by splitting theString
at the delimiter positions and adding those chunks to theList
.protected static java.util.List<java.lang.String>
fromSplitValues(java.lang.String aValues, java.lang.String aDelimiters)
Takes theString
and creates aList
withString
instances containing the elements as identified from theString
by splitting theString
at the delimiter positions and adding those chunks to theList
.CsvEscapeMode
getCsvEscapeMode()
Retrieves the CSV escape mode from the CSV escape mode property.char
getDelimiterChar()
Retrieves the delimiter char from the delimiter char property.java.util.Collection<java.lang.Object>
getFields()
Retrieves the CSV elements from the CSV elements property.java.lang.String
getRecord()
Retrieves the CSV line from the CSV line property.void
setCsvEscapeMode(CsvEscapeMode aCsvEscapeMode)
Sets the CSV escape mode for the CSV escape mode property.void
setDelimiterChar(char aDelimiterChar)
Sets the delimiter char for the delimiter char property.void
setFields(java.lang.Object... aFields)
Sets the CSV elements for the CSV elements property.void
setFields(java.util.Collection<java.lang.Object> aFields)
Sets the CSV elements for the CSV elements property.void
setRecord(java.lang.String aRecord)
Sets the CSV line for the CSV line property.protected static java.lang.String
toEscapedRegexp(char aDelimiter)
To escaped regexp.java.util.List<java.lang.String>
toFields()
Creates a list ofString
elements from the CSV line being set viaCsvBuilder.setRecord(String)
orCsvBuilder.withRecord(String)
.java.lang.String
toRecord()
Creates a CSV line from the elements being set viaCsvBuilder.setFields(String[])
orCsvBuilder.withFields(String[])
.java.lang.String
toRecord(java.lang.Object... aFields)
Creates a CSV line from the fields being provided This method is to be side effect free in terms of the fields (and the resulting record) is not part of the state for this instance (from the point of view of this method).java.lang.String
toRecord(java.lang.String... aFields)
Creates a CSV line from the fields being provided This method is to be side effect free in terms of the fields (and the resulting record) is not part of the state for this instance (from the point of view of this method).java.lang.String
toRecord(java.util.Collection<java.lang.Object> aFields)
Creates a CSV line from the fields being provided This method is to be side effect free in terms of the fields (and the resulting record) is not part of the state for this instance (from the point of view of this method).protected static java.lang.String
toSeparatedValue(java.lang.Object aValue)
Escapes a single value according to the rules of CSV like separated values with the accordingDelimiter.CSV
delimiter.protected static java.lang.String
toSeparatedValue(java.lang.Object aValue, char aDelimiter)
Escapes a single value according to the rules of CSV like separated values.protected static java.lang.String
toSeparatedValues(java.lang.Object[] aArray)
Takes the array'sString
representation and creates a singleString
with the accordingDelimiter.CSV
delimiter.protected static java.lang.String
toSeparatedValues(java.lang.Object[] aArray, char aDelimiter)
Takes the array's String representation and creates a singleString
with the provided delimiter.protected static java.lang.String
toSeparatedValues(java.util.Collection<?> aCollection)
Takes the collection and creates a singleString
with the accordingDelimiter.CSV
delimiter.protected static java.lang.String
toSeparatedValues(java.util.Collection<?> aCollection, char aDelimiter)
Takes the collection and creates a singleString
with the provided delimiter.protected static java.lang.String
toSeparatedValues(java.util.Collection<java.lang.Object> aFields, char aDelimiter, CsvEscapeMode aCsvEscapeMode)
To separated values.protected static java.lang.String
toSplitValue(java.lang.Object aValue, char aDelimiter)
Creates theString
representation of a single split value not applying any escaping.protected static java.lang.String
toSplitValues(java.lang.Object[] aArray)
Takes the array'sString
representation and creates a singleString
with the accordingDelimiter.CSV
delimiter.protected static java.lang.String
toSplitValues(java.lang.Object[] aArray, char aDelimiter)
Takes the array's String representation and creates a singleString
with the provided delimiter.protected static java.lang.String
toSplitValues(java.util.Collection<?> aCollection)
Takes the collection and creates a singleString
with the accordingDelimiter.CSV
delimiter.protected static java.lang.String
toSplitValues(java.util.Collection<?> aCollection, char aDelimiter)
Takes the collection and creates a singleString
with the provided delimiter.java.lang.String
toString()
TheString
being build by the builder upon the settings of the attributes.java.lang.String[]
toStrings()
Creates an array ofString
s from the CSV line being set viaCsvBuilder.setRecord(String)
orCsvBuilder.withRecord(String)
.java.lang.String[]
toStrings(java.lang.String aRecord)
Creates an array ofString
s from the CSV line being set viaCsvBuilder.setRecord(String)
orCsvBuilder.withRecord(String)
.-
Methods inherited from interface org.refcodes.textual.CsvBuilder
setFields, setFields, setFields, setFields, setFields, setFields, setFields, setFields, setFields, setFields, setFields, setFields, setFields, setFields, setFields, setFields, setFields, toFields, toRecord, toRecord, toRecord, toRecord, toRecord, toRecord, toRecord, toRecord, toRecord, toRecord, toRecord, toRecord, toRecord, toRecord, toRecord, toRecord, withCsvEscapeMode, withDelimiterChar, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withFields, withRecord
-
-
-
-
Method Detail
-
getCsvEscapeMode
public CsvEscapeMode getCsvEscapeMode()
Retrieves the CSV escape mode from the CSV escape mode property.- Specified by:
getCsvEscapeMode
in interfaceCsvBuilder
- Returns:
- The CSV escape mode stored by the CSV escape mode property.
-
setCsvEscapeMode
public void setCsvEscapeMode(CsvEscapeMode aCsvEscapeMode)
Sets the CSV escape mode for the CSV escape mode property.- Specified by:
setCsvEscapeMode
in interfaceCsvBuilder
- Parameters:
aCsvEscapeMode
- The CSV escape mode to be stored by the align text mode property.
-
setRecord
public void setRecord(java.lang.String aRecord)
Sets the CSV line for the CSV line property.- Specified by:
setRecord
in interfaceCsvBuilder
- Parameters:
aRecord
- The CSV line to be stored by the CSV line property.
-
getRecord
public java.lang.String getRecord()
Retrieves the CSV line from the CSV line property.- Specified by:
getRecord
in interfaceCsvBuilder
- Returns:
- The CSV line stored by the CSV line property.
-
setFields
public void setFields(java.lang.Object... aFields)
Sets the CSV elements for the CSV elements property.- Specified by:
setFields
in interfaceCsvBuilder
- Parameters:
aFields
- The CSV elements to be stored by the CSV elements property.
-
getFields
public java.util.Collection<java.lang.Object> getFields()
Retrieves the CSV elements from the CSV elements property.- Specified by:
getFields
in interfaceCsvBuilder
- Returns:
- The CSV elements stored by the CSV elements property.
-
setFields
public void setFields(java.util.Collection<java.lang.Object> aFields)
Sets the CSV elements for the CSV elements property.- Specified by:
setFields
in interfaceCsvBuilder
- Parameters:
aFields
- The CSV elements to be stored by the CSV elements property.
-
getDelimiterChar
public char getDelimiterChar()
Retrieves the delimiter char from the delimiter char property.- Specified by:
getDelimiterChar
in interfaceCsvBuilder
- Returns:
- The delimiter char stored by the Separator char property.
-
setDelimiterChar
public void setDelimiterChar(char aDelimiterChar)
Sets the delimiter char for the delimiter char property.- Specified by:
setDelimiterChar
in interfaceCsvBuilder
- Parameters:
aDelimiterChar
- The delimiter char to be stored by the text align mode property.
-
toFields
public java.util.List<java.lang.String> toFields() throws java.lang.IllegalStateException
Creates a list ofString
elements from the CSV line being set viaCsvBuilder.setRecord(String)
orCsvBuilder.withRecord(String)
.- Specified by:
toFields
in interfaceCsvBuilder
- Returns:
- The elements created from the CSV line.
- Throws:
java.lang.IllegalStateException
- Thrown in case no elements have been set via theCsvBuilder.withFields(String[])
orCsvBuilder.setFields(String[])
methods.
-
toRecord
public java.lang.String toRecord() throws java.lang.IllegalStateException
Creates a CSV line from the elements being set viaCsvBuilder.setFields(String[])
orCsvBuilder.withFields(String[])
.- Specified by:
toRecord
in interfaceCsvBuilder
- Returns:
- The CSV line created from the CSV line.
- Throws:
java.lang.IllegalStateException
- Thrown in case no CSV line has been set via theCsvBuilder.withRecord(String)
orCsvBuilder.setRecord(String)
methods.
-
toRecord
public java.lang.String toRecord(java.lang.Object... aFields)
Creates a CSV line from the fields being provided This method is to be side effect free in terms of the fields (and the resulting record) is not part of the state for this instance (from the point of view of this method). Still changing for example the delimiter viaCsvBuilder.withDelimiterChar(char)
can cause side effects! For avoiding thread race conditions / side effects regarding the fields (and the resulting record), use this method instead of the combination ofCsvBuilder.withFields(String...)
withCsvBuilder.toRecord()
.- Specified by:
toRecord
in interfaceCsvBuilder
- Parameters:
aFields
- The CSV elements to be converted into a record.- Returns:
- The CSV line created from the fields.
-
toRecord
public java.lang.String toRecord(java.util.Collection<java.lang.Object> aFields)
Creates a CSV line from the fields being provided This method is to be side effect free in terms of the fields (and the resulting record) is not part of the state for this instance (from the point of view of this method). Still changing for example the delimiter viaCsvBuilder.withDelimiterChar(char)
can cause side effects! For avoiding thread race conditions / side effects regarding the fields (and the resulting record), use this method instead of the combination ofCsvBuilder.withFields(String...)
withCsvBuilder.toRecord()
.- Specified by:
toRecord
in interfaceCsvBuilder
- Parameters:
aFields
- The CSV elements to be converted into a record.- Returns:
- The CSV line created from the fields.
-
toStrings
public java.lang.String[] toStrings() throws java.lang.IllegalStateException
Creates an array ofString
s from the CSV line being set viaCsvBuilder.setRecord(String)
orCsvBuilder.withRecord(String)
. It should return the same result as an array as a call toCsvBuilder.toFields()
.- Specified by:
toStrings
in interfaceCsvBuilder
- Returns:
- The elements created from the CSV line.
- Throws:
java.lang.IllegalStateException
-
toRecord
public java.lang.String toRecord(java.lang.String... aFields) throws java.lang.IllegalStateException
Creates a CSV line from the fields being provided This method is to be side effect free in terms of the fields (and the resulting record) is not part of the state for this instance (from the point of view of this method). Still changing for example the delimiter viaCsvBuilder.withDelimiterChar(char)
can cause side effects! For avoiding thread race conditions / side effects regarding the fields (and the resulting record), use this method instead of the combination ofCsvBuilder.withFields(String...)
withCsvBuilder.toRecord()
.- Specified by:
toRecord
in interfaceCsvBuilder
- Parameters:
aFields
- The CSV elements to be converted into a record.- Returns:
- The CSV line created from the fields.
- Throws:
java.lang.IllegalStateException
-
toStrings
public java.lang.String[] toStrings(java.lang.String aRecord)
Creates an array ofString
s from the CSV line being set viaCsvBuilder.setRecord(String)
orCsvBuilder.withRecord(String)
. It should return the same result as an array as a call toCsvBuilder.toFields()
. This method is to be side effect free in terms of the record (and the resulting fields) is not part of the state for this instance (from the point of view of this method). Still changing for example the delimiter viaCsvBuilder.withDelimiterChar(char)
can cause side effects! For avoiding thread race conditions / side effects regarding the record (and the resulting fields), use this method instead of the combination ofCsvBuilder.withRecord(String)
withCsvBuilder.toStrings()
.- Specified by:
toStrings
in interfaceCsvBuilder
- Parameters:
aRecord
- The CSV line to be stored by the CSV line property.- Returns:
- The elements created from the CSV line.
-
toString
public java.lang.String toString() throws java.lang.IllegalStateException
TheString
being build by the builder upon the settings of the attributes. It should return the same result as a call toCsvBuilder.toRecord()
.- Specified by:
toString
in interfaceCsvBuilder
- Overrides:
toString
in classjava.lang.Object
- Returns:
- The according resulting
String
- Throws:
java.lang.IllegalStateException
-
fromSeparatedValues
protected static java.util.List<java.lang.String> fromSeparatedValues(java.lang.String aRecord, char aDelimiter, CsvEscapeMode aCsvEscapeMode)
From separated values.- Parameters:
aRecord
- the recordaDelimiter
- the delimiteraCsvEscapeMode
- the csv escape mode- Returns:
- the list
-
toSeparatedValues
protected static java.lang.String toSeparatedValues(java.util.Collection<java.lang.Object> aFields, char aDelimiter, CsvEscapeMode aCsvEscapeMode)
To separated values.- Parameters:
aFields
- the fieldsaDelimiter
- the delimiteraCsvEscapeMode
- the csv escape mode- Returns:
- the string
-
toSeparatedValues
protected static java.lang.String toSeparatedValues(java.util.Collection<?> aCollection)
Takes the collection and creates a singleString
with the accordingDelimiter.CSV
delimiter. Unescaping any escaped chars is taken care of by this method, for example an unescaped delimiter char is escaped in the result.- Parameters:
aCollection
- The collection to be converted to a single CSVString
.- Returns:
- The single CSV
String
from the collection.
-
toSeparatedValues
protected static java.lang.String toSeparatedValues(java.util.Collection<?> aCollection, char aDelimiter)
Takes the collection and creates a singleString
with the provided delimiter. Unescaping any escaped chars is taken care of by this method, for example an unescaped delimiter char is escaped in the result.- Parameters:
aCollection
- The collection to be converted to a single CSVString
.aDelimiter
- The delimiter to use for creating the single CSVString
.- Returns:
- The single CSV
String
from the collection.
-
toSeparatedValue
protected static java.lang.String toSeparatedValue(java.lang.Object aValue)
Escapes a single value according to the rules of CSV like separated values with the accordingDelimiter.CSV
delimiter.- Parameters:
aValue
- The value which'sString
representation is to be escaped accordingly.- Returns:
- A single value escaped according to the rules of CSV like separated values.
-
toSeparatedValue
protected static java.lang.String toSeparatedValue(java.lang.Object aValue, char aDelimiter)
Escapes a single value according to the rules of CSV like separated values.- Parameters:
aValue
- The value which'sString
representation is to be escaped accordingly.aDelimiter
- The delimiter to use for creating the single CSVString
.- Returns:
- A single value escaped according to the rules of CSV like separated values.
-
fromSeparatedValues
protected static java.util.List<java.lang.String> fromSeparatedValues(java.lang.String aSeparatedValues)
Takes theString
and creates aList
withString
instances containing the elements as identified from theString
by splitting theString
at the delimiter positions and adding those chunks to theList
with the accordingDelimiter.CSV
delimiter.. Escaping any unescaped chars is taken care of by this method, for example an escaped delimiter char is unescaped in the result.- Parameters:
aSeparatedValues
- TheString
representing the CSVString
where contained elements are separated from each other by the given delimiter.- Returns:
- The
List
containing the elements as identified from the given CSVString
.
-
fromSeparatedValues
protected static java.util.List<java.lang.String> fromSeparatedValues(java.lang.String aSeparatedValues, char aDelimiter)
Takes theString
and creates aList
withString
instances containing the elements as identified from theString
by splitting theString
at the delimiter positions and adding those chunks to theList
. Escaping any unescaped chars is taken care of by this method, for example an escaped delimiter char is unescaped in the result.- Parameters:
aSeparatedValues
- TheString
representing the CSVString
where contained elements are separated from each other by the given delimiter.aDelimiter
- The delimiter used for separating the elements if the single CSVString
.- Returns:
- The
List
containing the elements as identified from the given CSVString
.
-
toSplitValues
protected static java.lang.String toSplitValues(java.lang.Object[] aArray)
Takes the array'sString
representation and creates a singleString
with the accordingDelimiter.CSV
delimiter. No escaping is taken care of, for escaping either use the accordingtoSeparatedValues(Object[])
method or do escaping manually.- Parameters:
aArray
- The array to be converted to a single CSVString
.- Returns:
- The single CSV
String
from theString
array.
-
toSplitValues
protected static java.lang.String toSplitValues(java.lang.Object[] aArray, char aDelimiter)
Takes the array's String representation and creates a singleString
with the provided delimiter. No escaping is taken of, for escaping either use the accordingtoSeparatedValues(Object[], char)
method or do escaping manually.- Parameters:
aArray
- The array to be converted to a single CSVString
.aDelimiter
- The delimiter to use for creating the single CSVString
.- Returns:
- The single CSV
String
from theString
array.
-
toSplitValues
protected static java.lang.String toSplitValues(java.util.Collection<?> aCollection)
Takes the collection and creates a singleString
with the accordingDelimiter.CSV
delimiter. No escaping is taken of, for escaping either use the accordingtoSeparatedValues(java.util.Collection<java.lang.Object>,char,org.refcodes.textual.CsvEscapeMode)
method or do escaping manually viatoSeparatedValue(java.lang.Object)
.- Parameters:
aCollection
- The collection to be converted to a single CSVString
.- Returns:
- The single CSV
String
from the collection.
-
toSplitValues
protected static java.lang.String toSplitValues(java.util.Collection<?> aCollection, char aDelimiter)
Takes the collection and creates a singleString
with the provided delimiter. No escaping is taken of, for escaping either use the accordingtoSeparatedValues(java.util.Collection<java.lang.Object>,char,org.refcodes.textual.CsvEscapeMode)
method or do escaping manually viatoSeparatedValue(java.lang.Object)
.- Parameters:
aCollection
- The collection to be converted to a single CSVString
.aDelimiter
- The delimiter to use for creating the single CSVString
.- Returns:
- The single CSV
String
from the collection.
-
toSplitValue
protected static java.lang.String toSplitValue(java.lang.Object aValue, char aDelimiter)
Creates theString
representation of a single split value not applying any escaping.- Parameters:
aValue
- The value which'sString
representation is to be retrieved.aDelimiter
- The delimiter to use for creating the single CSVString
.- Returns:
- A single value not escaped as required by plain split values.
-
fromSplitValues
protected static java.util.List<java.lang.String> fromSplitValues(java.lang.String aSplitValues)
Takes theString
and creates aList
withString
instances containing the elements as identified from theString
by splitting theString
at the delimiter positions and adding those chunks to theList
with the accordingDelimiter.CSV
delimiter.. Escaping any unescaped chars is taken care of by this method, for example an escaped delimiter char is unescaped in the result.- Parameters:
aSplitValues
- TheString
representing the CSVString
where contained elements are split from each other by the given delimiter.- Returns:
- The
List
containing the elements as identified from the given CSVString
.
-
fromSplitValues
protected static java.util.List<java.lang.String> fromSplitValues(java.lang.String aSplitValues, char aDelimiter)
Takes theString
and creates aList
withString
instances containing the elements as identified from theString
by splitting theString
at the delimiter positions and adding those chunks to theList
. Escaping any unescaped chars is taken care of by this method, for example an escaped delimiter char is unescaped in the result.- Parameters:
aSplitValues
- TheString
representing the CSVString
where contained elements are split from each other by the given delimiter.aDelimiter
- The delimiter used for separating the elements if the single CSVString
.- Returns:
- The
List
containing the elements as identified from the given CSVString
.
-
fromSplitValues
protected static java.util.List<java.lang.String> fromSplitValues(java.lang.String aValues, java.lang.String aDelimiters)
Takes theString
and creates aList
withString
instances containing the elements as identified from theString
by splitting theString
at the delimiter positions and adding those chunks to theList
. Escaping any unescaped chars is taken care of by this method, for example an escaped delimiter char is unescaped in the result.- Parameters:
aValues
- TheString
representing the CSVString
where contained elements are separated from each other by the given delimiter.aDelimiters
- The delimiter characters used for separating the elements.- Returns:
- The
List
containing the elements as identified from the given CSVString
.
-
toSeparatedValues
protected static java.lang.String toSeparatedValues(java.lang.Object[] aArray)
Takes the array'sString
representation and creates a singleString
with the accordingDelimiter.CSV
delimiter. Unescaping any escaped chars is taken care of by this method, for example an unescaped delimiter char is escaped in the result.- Parameters:
aArray
- The array to be converted to a single CSVString
.- Returns:
- The single CSV
String
from theString
array.
-
toSeparatedValues
protected static java.lang.String toSeparatedValues(java.lang.Object[] aArray, char aDelimiter)
Takes the array's String representation and creates a singleString
with the provided delimiter. Unescaping any escaped chars is taken care of by this method, for example an unescaped delimiter char is escaped in the result.- Parameters:
aArray
- The array to be converted to a single CSVString
.aDelimiter
- The delimiter to use for creating the single CSVString
.- Returns:
- The single CSV
String
from theString
array.
-
toEscapedRegexp
protected static java.lang.String toEscapedRegexp(char aDelimiter)
To escaped regexp.- Parameters:
aDelimiter
- the delimiter- Returns:
- the string
-
-