This commit is contained in:
Gary Gregory 2023-08-26 08:06:55 -04:00
parent 47ff95dbfc
commit 87529dea16
1 changed files with 108 additions and 18 deletions

View File

@ -313,9 +313,34 @@ public final class CSVFormat implements Serializable {
}
/**
* Sets the comment start marker, use {@code null} to disable.
*
* Note that the comment start character is only recognized at the start of a line.
* Sets the comment marker character, use {@code null} to disable comments.
* <p>
* The comment start character is only recognized at the start of a line.
* </p>
* <p>
* Comments are printed first, before headers.
* </p>
* <p>
* Use {@link #setCommentMarker(char)} or {@link #setCommentMarker(Character)} to set the comment marker written at the start of
* each comment line.
* </p>
* <p>
* If the comment marker is not set, then the header comments are ignored.
* </p>
* <p>
* For example:
* </p>
* <pre>
* builder.setCommentMarker('#')
* .setHeaderComments("Generated by Apache Commons CSV", Instant.ofEpochMilli(0));
* </pre>
* <p>
* writes:
* </p>
* <pre>
* # Generated by Apache Commons CSV.
* # 1970-01-01T00:00:00Z
* </pre>
*
* @param commentMarker the comment start marker, use {@code null} to disable.
* @return This instance.
@ -327,9 +352,34 @@ public final class CSVFormat implements Serializable {
}
/**
* Sets the comment start marker, use {@code null} to disable.
*
* Note that the comment start character is only recognized at the start of a line.
* Sets the comment marker character, use {@code null} to disable comments.
* <p>
* The comment start character is only recognized at the start of a line.
* </p>
* <p>
* Comments are printed first, before headers.
* </p>
* <p>
* Use {@link #setCommentMarker(char)} or {@link #setCommentMarker(Character)} to set the comment marker written at the start of
* each comment line.
* </p>
* <p>
* If the comment marker is not set, then the header comments are ignored.
* </p>
* <p>
* For example:
* </p>
* <pre>
* builder.setCommentMarker('#')
* .setHeaderComments("Generated by Apache Commons CSV", Instant.ofEpochMilli(0));
* </pre>
* <p>
* writes:
* </p>
* <pre>
* # Generated by Apache Commons CSV.
* # 1970-01-01T00:00:00Z
* </pre>
*
* @param commentMarker the comment start marker, use {@code null} to disable.
* @return This instance.
@ -521,7 +571,7 @@ public final class CSVFormat implements Serializable {
}
/**
* Sets the header comments to the given values before the CSV data.
* Sets the header comments to write before the CSV data.
* <p>
* This setting is ignored by the parser.
* </p>
@ -529,7 +579,7 @@ public final class CSVFormat implements Serializable {
* Comments are printed first, before headers.
* </p>
* <p>
* Use {@link Builder#setCommentMarker(char)} or {@link Builder#setCommentMarker(Character)} to set the comment marker written at the start of
* Use {@link #setCommentMarker(char)} or {@link #setCommentMarker(Character)} to set the comment marker written at the start of
* each comment line.
* </p>
* <p>
@ -553,14 +603,13 @@ public final class CSVFormat implements Serializable {
* @param headerComments the headerComments which will be printed by the Printer before the CSV data.
* @return This instance.
*/
public Builder setHeaderComments(final Object... headerComments) {
this.headerComments = CSVFormat.clone(toStringArray(headerComments));
return this;
}
/**
* Sets the header comments to the given values before the CSV data.
* Sets the header comments to write before the CSV data.
* <p>
* This setting is ignored by the parser.
* </p>
@ -568,7 +617,7 @@ public final class CSVFormat implements Serializable {
* Comments are printed first, before headers.
* </p>
* <p>
* Use {@link Builder#setCommentMarker(char)} or {@link Builder#setCommentMarker(Character)} to set the comment marker written at the start of
* Use {@link #setCommentMarker(char)} or {@link #setCommentMarker(Character)} to set the comment marker written at the start of
* each comment line.
* </p>
* <p>
@ -1570,19 +1619,33 @@ public final class CSVFormat implements Serializable {
}
/**
* Gets the character marking the start of a line comment.
* Gets the comment marker character, {@code null} disables comments.
* <p>
* The comment format for each line is:
* The comment start character is only recognized at the start of a line.
* </p>
* <p>
* Comments are printed first, before headers.
* </p>
* <p>
* Use {@link Builder#setCommentMarker(char)} or {@link Builder#setCommentMarker(Character)} to set the comment
* marker written at the start of each comment line.
* </p>
* <p>
* If the comment marker is not set, then the header comments are ignored.
* </p>
* <p>
* For example:
* </p>
* <pre>
* CommentMarker SPACE CommentArrayElement
* builder.setCommentMarker('#')
* .setHeaderComments("Generated by Apache Commons CSV", Instant.ofEpochMilli(0));
* </pre>
* <p>
* For example, using a comment marker {@code '#'} and a comment array {@code comments ["line 1", "line 2"]}:
* writes:
* </p>
* <pre>
* # line 1
* # line 2
* # Generated by Apache Commons CSV.
* # 1970-01-01T00:00:00Z
* </pre>
*
* @return the comment start marker, may be {@code null}
@ -1641,7 +1704,34 @@ public final class CSVFormat implements Serializable {
}
/**
* Gets a copy of the header comment array.
* Gets a copy of the header comment array to write before the CSV data.
* <p>
* This setting is ignored by the parser.
* </p>
* <p>
* Comments are printed first, before headers.
* </p>
* <p>
* Use {@link Builder#setCommentMarker(char)} or {@link Builder#setCommentMarker(Character)} to set the comment
* marker written at the start of each comment line.
* </p>
* <p>
* If the comment marker is not set, then the header comments are ignored.
* </p>
* <p>
* For example:
* </p>
* <pre>
* builder.setCommentMarker('#')
* .setHeaderComments("Generated by Apache Commons CSV", Instant.ofEpochMilli(0));
* </pre>
* <p>
* writes:
* </p>
* <pre>
* # Generated by Apache Commons CSV.
* # 1970-01-01T00:00:00Z
* </pre>
*
* @return a copy of the header comment array; {@code null} if disabled.
*/