Top Description Inners Fields Constructors Methods
de.siegmar.fastcsv.reader

public final Class NamedCsvRecordHandler

extends AbstractInternalCsvCallbackHandler<NamedCsvRecord>
Class Inheritance
Imports
java.util.HashSet, .LinkedHashSet, .List, .Objects, java.util.function.Consumer, de.siegmar.fastcsv.util.Nullable

A callback handler that returns a NamedCsvRecord for each record.

Example:

NamedCsvRecordHandler handler = NamedCsvRecordHandler.builder() .fieldModifier(FieldModifiers.TRIM) .header("foo", "bar") .build();
NamedCsvRecordHandler handler = NamedCsvRecordHandler.builder()
    .fieldModifier(FieldModifiers.TRIM)
    .header("foo", "bar")
    .build();

This implementation is stateful and must not be reused.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final boolean
private static final String[]
private String[]
private final boolean
Inherited from de.siegmar.fastcsv.reader.AbstractInternalCsvCallbackHandler:
fieldIdxfieldModifierfieldsmaxFieldsmaxFieldSizemaxRecordSizerecordSizerecordTypestartingLineNumber

Constructor Summary

AccessConstructor and Description
private
NamedCsvRecordHandler(final int maxFields, final int maxFieldSize, final int maxRecordSize, final FieldModifier fieldModifier, final boolean allowDuplicateHeaderFields, final boolean returnHeader, final List<String> header)

Method Summary

Modifier and TypeMethod and Description
public static NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder

Returns:

the builder
builder
()

Constructs a new builder instance for this class.

protected NamedCsvRecord
buildRecord()

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.buildRecord.

Called at the end of each CSV record to build the actual record representation.

private static void
checkForDuplicates(final String[] header)

public static NamedCsvRecordHandler

Returns:

the new instance
of
()

Constructs a new instance of this class with default settings.

public static NamedCsvRecordHandler

Returns:

the new instance
of
(final Consumer<NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder>
the configuration, must not be null
configurer
)

Constructs a new instance of this class with the given configuration.

private String[]
validateHeader(final String[] fields)

Inherited from de.siegmar.fastcsv.reader.AbstractInternalCsvCallbackHandler:
addFieldbeginRecordcompactFieldsgetFieldCountgetRecordTypemodifyCommentmodifyFieldsetCommentsetEmpty

Field Detail

allowDuplicateHeaderFieldsback to summary
private final boolean allowDuplicateHeaderFields
EMPTY_HEADERback to summary
private static final String[] EMPTY_HEADER
returnHeaderback to summary
private final boolean returnHeader

Constructor Detail

NamedCsvRecordHandlerback to summary
private NamedCsvRecordHandler(final int maxFields, final int maxFieldSize, final int maxRecordSize, final FieldModifier fieldModifier, final boolean allowDuplicateHeaderFields, final boolean returnHeader, final List<String> header)

Method Detail

builderback to summary
public static NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder builder()

Constructs a new builder instance for this class.

Returns:NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder

the builder

See Also
of(Consumer)
buildRecordback to summary
protected NamedCsvRecord buildRecord()

Implements abstract de.siegmar.fastcsv.reader.CsvCallbackHandler.buildRecord.

Doc from de.siegmar.fastcsv.reader.CsvCallbackHandler.buildRecord.

Called at the end of each CSV record to build the actual record representation.

Annotations
@Nullable
@Override
checkForDuplicatesback to summary
private static void checkForDuplicates(final String[] header)
Annotations
@SuppressWarnings:PMD.UseVarargs
ofback to summary
public static NamedCsvRecordHandler of()

Constructs a new instance of this class with default settings.

Returns:NamedCsvRecordHandler

the new instance

See Also
NamedCsvRecordHandlerBuilder#build()
ofback to summary
public static NamedCsvRecordHandler of(final Consumer<NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder> configurer)

Constructs a new instance of this class with the given configuration.

This is an alternative to the builder pattern for convenience.

Parameters
configurer:Consumer<NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder>

the configuration, must not be null

Returns:NamedCsvRecordHandler

the new instance

Exceptions
NullPointerException:
if null is passed
IllegalArgumentException:
if argument constraints are violated
See Also
builder()
validateHeaderback to summary
private String[] validateHeader(final String[] fields)
Annotations
@SuppressWarnings:PMD.UseVarargs
de.siegmar.fastcsv.reader back to summary

public final Class NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder

extends AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder<NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder>
Class Inheritance
Annotations
@SuppressWarnings:checkstyle:HiddenField, PMD.AvoidFieldNameMatchingMethodName

A builder for NamedCsvRecordHandler.

Field Summary

Modifier and TypeField and Description
private boolean
private List<String>
private boolean
Inherited from de.siegmar.fastcsv.reader.AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder:
fieldModifiermaxFieldsmaxFieldSizemaxRecordSize

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder

Returns:

This updated object, allowing additional method calls to be chained together.
allowDuplicateHeaderFields
(final boolean
whether duplicate header fields are allowed (default: false)
allowDuplicateHeaderFields
)

Sets whether duplicate header fields are allowed.

public NamedCsvRecordHandler

Returns:

the new instance
build
()

Builds the NamedCsvRecordHandler instance.

public NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder

Returns:

This updated object, allowing additional method calls to be chained together.
header
(final String...
the header, must not be null
header
)

Sets a predefined header.

public NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder

Returns:

This updated object, allowing additional method calls to be chained together.
header
(final List<String>
the header, must not be null
header
)

Sets the header.

public NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder

Returns:

This updated object, allowing additional method calls to be chained together.
returnHeader
(final boolean
whether the header should be returned as the first record (default: false)
returnHeader
)

Sets whether the header itself should be returned as the first record.

protected NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder
self()

Implements abstract de.siegmar.fastcsv.reader.AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder.self.

Method to be implemented by subclasses to return the correct type.

Inherited from de.siegmar.fastcsv.reader.AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder:
fieldModifiermaxFieldsmaxFieldSizemaxRecordSize

Field Detail

allowDuplicateHeaderFieldsback to summary
private boolean allowDuplicateHeaderFields
headerback to summary
private List<String> header
Annotations
@Nullable
returnHeaderback to summary
private boolean returnHeader

Constructor Detail

NamedCsvRecordHandlerBuilderback to summary
private NamedCsvRecordHandlerBuilder()

Method Detail

allowDuplicateHeaderFieldsback to summary
public NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder allowDuplicateHeaderFields(final boolean allowDuplicateHeaderFields)

Sets whether duplicate header fields are allowed.

When set to false, an IllegalArgumentException is thrown if the header contains duplicate fields. When set to true, duplicate fields are allowed. See NamedCsvRecord for details on how duplicate headers are handled.

Parameters
allowDuplicateHeaderFields:boolean

whether duplicate header fields are allowed (default: false)

Returns:NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder

This updated object, allowing additional method calls to be chained together.

buildback to summary
public NamedCsvRecordHandler build()

Builds the NamedCsvRecordHandler instance.

Returns:NamedCsvRecordHandler

the new instance

Exceptions
IllegalArgumentException:
if argument constraints are violated (see AbstractInternalCsvCallbackHandler)
headerback to summary
public NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder header(final String... header)

Sets a predefined header.

When not set, the header is taken from the first record (that is not a comment).

Parameters
header:String[]

the header, must not be null

Returns:NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder

This updated object, allowing additional method calls to be chained together.

Annotations
@SuppressWarnings:checkstyle:HiddenField
Exceptions
NullPointerException:
if null is passed
See Also
header(List)
headerback to summary
public NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder header(final List<String> header)

Sets the header.

When not set, the header is taken from the first record (that is not a comment).

Parameters
header:List<String>

the header, must not be null

Returns:NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder

This updated object, allowing additional method calls to be chained together.

Annotations
@SuppressWarnings:checkstyle:HiddenField
Exceptions
NullPointerException:
if null is passed
See Also
header(String...)
returnHeaderback to summary
public NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder returnHeader(final boolean returnHeader)

Sets whether the header itself should be returned as the first record.

When enabled, the first record returned will be a NamedCsvRecord with the header fields as its fields and as the header.

Parameters
returnHeader:boolean

whether the header should be returned as the first record (default: false)

Returns:NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder

This updated object, allowing additional method calls to be chained together.

selfback to summary
protected NamedCsvRecordHandler.NamedCsvRecordHandlerBuilder self()

Implements abstract de.siegmar.fastcsv.reader.AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder.self.

Doc from de.siegmar.fastcsv.reader.AbstractInternalCsvCallbackHandler.AbstractInternalCsvCallbackHandlerBuilder.self.

Method to be implemented by subclasses to return the correct type.

Annotations
@Override