Hi Team.

I am new to the Apache mailing list and I would like to contribute.
I was trying some samples with Apache CSV library and I have one JavaDoc.
optimization suggestion.

Scenario:

If we want to set a header comment in the CSV when writing a new CSV
content, we can achieve it by doing the following.

CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
    .setHeader(headerList.toArray(new String[0]))
    .setDelimiter(",")
    .setHeaderComments("Sample header comment one", "Sample header comment
two")
    .setCommentMarker('-')
    .build();

In this case if we do not set the comment marker with method
'setCommentMarker('-')', then no header comment gets printed.
This is obvious, but when a developer looking at the code for the first
time, I think it would be best if we can specify a simple comment in the
JavaDoc for the method 'setHeaderComments()' to explicitly mention that, it
is also required to set the comment marker inorder to get header comments
working properly.
Or else, we could throw some exception with a message similar to: "No
comment marker has been set".

Currently we have the following method comment set for
'setHeaderComments()'.

/**
 * Sets the header comments set to the given values. The comments will be
printed first, before the headers. This setting is ignored by the parser.
 *
 * <pre>
 * Builder.setHeaderComments(&quot;Generated by Apache Commons CSV.&quot;,
Instant.now());
 * </pre>
 *
 * @param headerComments the headerComments which will be printed by the
Printer before the actual CSV data.
 * @return This instance.
 */

And following is the method where header comments are getting printed. If
the comment marker is not set, it simply returns.

public synchronized void printComment(final String comment) throws
IOException {
    if (comment == null || !format.isCommentMarkerSet()) {
        return;
    }
}

Your feedback is welcome!

Reply via email to