[ 
https://issues.apache.org/jira/browse/CSV-304?focusedWorklogId=806523&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-806523
 ]

ASF GitHub Bot logged work on CSV-304:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 06/Sep/22 20:53
            Start Date: 06/Sep/22 20:53
    Worklog Time Spent: 10m 
      Work Description: kinow commented on code in PR #257:
URL: https://github.com/apache/commons-csv/pull/257#discussion_r964097158


##########
src/main/java/org/apache/commons/csv/CSVParser.java:
##########
@@ -596,7 +601,49 @@ Map<String, Integer> getHeaderMapRaw() {
     public List<String> getHeaderNames() {
         return Collections.unmodifiableList(headers.headerNames);
     }
-
+    /**
+     * Checks whether this parser has a header comment, false otherwise.
+     * The header comment appears before the header record.
+     * Note that if the parser's format has been given an explicit header
+     * (with {@link CSVFormat.Builder#setHeader(String... )} or another 
overload)
+     * and the header record is not being skipped
+     * ({@link CSVFormat.Builder#setSkipHeaderRecord} is false) then any 
initial comments
+     * will be associated with the first record, not the header.
+     *
+     * @return true if this parser has seen a header comment, false otherwise
+     */
+    public boolean hasHeaderComment() {
+        return headerComment != null;
+    }
+    /**
+     * Returns the header comment for this parser, if any.
+     * The header comment appears before the header record.
+     *
+     * @return the header comment for this stream, or null if no comment is 
available.
+     */
+    public String getHeaderComment() {
+        return headerComment;
+    }
+    /**
+     * Checks whether this parser has seen a trailer comment, false otherwise.
+     * Trailer comments are located between the last record and EOF.
+     * The trailer comments will only be available after the parser has
+     * finished processing this stream.
+     *
+     * @return true if this parser has seen a trailer comment, false otherwise
+     */
+    public boolean hasTrailerComment() {
+        return trailerComment != null;
+    }
+    /**
+     * Returns the trailer comment for this record, if any.
+     * Trailer comments are located between the last record and EOF
+     *
+     * @return the trailer comment for this stream, or null if no comment is 
available.
+     */
+    public String getTrailerComment() {
+        return trailerComment;
+    }

Review Comment:
   New public methods need a `@since ` tag with the version. The version is the 
`version-SNAPSHOT` from the `pom.xml`, without the `-SNAPSHOT` suffix (i.e. 
next release version).





Issue Time Tracking
-------------------

    Worklog Id:     (was: 806523)
    Time Spent: 0.5h  (was: 20m)

> Provide access methods for header and trailer comments
> ------------------------------------------------------
>
>                 Key: CSV-304
>                 URL: https://issues.apache.org/jira/browse/CSV-304
>             Project: Commons CSV
>          Issue Type: Improvement
>          Components: Parser
>    Affects Versions: 1.9.0
>            Reporter: Peter Hull
>            Priority: Minor
>             Fix For: Discussion
>
>         Attachments: header-comment.patch
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The Apache Commons CSV library can deal with comments by attaching the 
> comment to the following record.
> It does not seem possible to access comments that are before the header line 
> ("header comments"), or after the last record ("trailer comments")
> I feel this would be a useful enhancement to the current comment-handling 
> features of version 1.9.
> I have not been able to find mention of this in other JIRA tickets.
> I have attached a patch implementing this, for discussion purposes. (n.b. I 
> had trouble with git showing spurious ^M at the end of changed lines in 
> CSVParserTest.java which I could not get rid of)
> This adds methods String CSVParser::getHeaderComment(), String 
> CSVParser::getTrailerComment(), bool CSVParser::hasHeaderComment() and bool 
> CSVParser::hasTrailerComment() . The last two could be omitted assuming a 
> missing comment would return a null String.
>  
> See also 
> [https://stackoverflow.com/questions/72619095/get-leading-comments-from-csv-with-apache-commons-csv]
>  and [https://lists.apache.org/thread/8tczpqlnjgbcyovyhb484tt11vqv91jt]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to