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. * Sets the comment marker character, use {@code null} to disable comments.
* * <p>
* Note that the comment start character is only recognized at the start of a line. * 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. * @param commentMarker the comment start marker, use {@code null} to disable.
* @return This instance. * @return This instance.
@ -327,9 +352,34 @@ public final class CSVFormat implements Serializable {
} }
/** /**
* Sets the comment start marker, use {@code null} to disable. * Sets the comment marker character, use {@code null} to disable comments.
* * <p>
* Note that the comment start character is only recognized at the start of a line. * 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. * @param commentMarker the comment start marker, use {@code null} to disable.
* @return This instance. * @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> * <p>
* This setting is ignored by the parser. * This setting is ignored by the parser.
* </p> * </p>
@ -529,7 +579,7 @@ public final class CSVFormat implements Serializable {
* Comments are printed first, before headers. * Comments are printed first, before headers.
* </p> * </p>
* <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. * each comment line.
* </p> * </p>
* <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. * @param headerComments the headerComments which will be printed by the Printer before the CSV data.
* @return This instance. * @return This instance.
*/ */
public Builder setHeaderComments(final Object... headerComments) { public Builder setHeaderComments(final Object... headerComments) {
this.headerComments = CSVFormat.clone(toStringArray(headerComments)); this.headerComments = CSVFormat.clone(toStringArray(headerComments));
return this; 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> * <p>
* This setting is ignored by the parser. * This setting is ignored by the parser.
* </p> * </p>
@ -568,7 +617,7 @@ public final class CSVFormat implements Serializable {
* Comments are printed first, before headers. * Comments are printed first, before headers.
* </p> * </p>
* <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. * each comment line.
* </p> * </p>
* <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> * <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> * </p>
* <pre> * <pre>
* CommentMarker SPACE CommentArrayElement * builder.setCommentMarker('#')
* .setHeaderComments("Generated by Apache Commons CSV", Instant.ofEpochMilli(0));
* </pre> * </pre>
* <p> * <p>
* For example, using a comment marker {@code '#'} and a comment array {@code comments ["line 1", "line 2"]}: * writes:
* </p> * </p>
* <pre> * <pre>
* # line 1 * # Generated by Apache Commons CSV.
* # line 2 * # 1970-01-01T00:00:00Z
* </pre> * </pre>
* *
* @return the comment start marker, may be {@code null} * @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. * @return a copy of the header comment array; {@code null} if disabled.
*/ */