jomarko commented on code in PR #6195:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6195#discussion_r1883376169


##########
drools-decisiontables/src/main/java/org/drools/decisiontable/parser/csv/CsvLineParser.java:
##########
@@ -1,150 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.drools.decisiontable.parser.csv;
 
 import java.util.ArrayList;
 import java.util.List;
 
 /**
- * 
- *         a CSV line, with all the normal CSV features.
+ * A simple parser for CSV (Comma-Separated Values) format.
+ * Supports quoted fields, escaped quotes, and custom delimiters.
  */
 public class CsvLineParser {
-    private ICsvParser lineParser;
-
-    public CsvLineParser() {
-        this.lineParser = new CsvParserImpl();
-    }
+    private final char delimiter;
 
     /**
-     * Use the current lineParser implementation to return a CSV line as a List
-     * of cells. (Strings).
+     * Creates a CSV parser with comma as the default delimiter.
      */
-    public List<String> parse(final CharSequence line) {
-        return this.lineParser.parse( line.toString() );
+    public CsvLineParser() {
+        this(',');
     }
 
     /**
-     * This is insurance incase I need to replace it with more complex Csv
-     * handlers in the future.
+     * Creates a CSV parser with a custom delimiter.
+     *
+     * @param delimiter The character to use as field delimiter
      */
-    static interface ICsvParser {
-        public List<String> parse(String line);
+    public CsvLineParser(char delimiter) {
+        this.delimiter = delimiter;
     }
 
     /**
-     * Parse comma-separated values (CSV), a common Windows file format. Sample
-     * input: "LU",86.25,"11/4/1998","2:19PM",+4.0625
-     * <p>
-     * Inner logic adapted from a C++ original that was Copyright (C) 1999
-     * Lucent Technologies Excerpted from 'The Practice of Programming' by 
Brian
-     * W. Kernighan and Rob Pike.
-     * <p>
-     * Included by permission of the http://tpop.awl.com/ web site, which says:
-     * "You may use this code for any purpose, as long as you leave the
-     * copyright notice and book citation attached." I have done so.
-     * 
-     *         readability)
+     * Parses a line of CSV text into a list of fields.
+     *
+     * @param input The CSV line to parse
+     * @return List of fields extracted from the CSV line
      */
-    static class CsvParserImpl
-        implements
-        ICsvParser {
-
-        public static final char DEFAULT_SEP = ',';
+    public List<String> parse(CharSequence input) {
+        String line = input != null ? input.toString() : "";
+        List<String> fields = new ArrayList<>();
 
-        /** Construct a CSV parser, with the default separator (','). */
-        public CsvParserImpl() {
-            this( CsvParserImpl.DEFAULT_SEP );
+        if (line.isEmpty()) {
+            fields.add("");
+            return fields;

Review Comment:
   In past, we used often `Collections.singletoneList`, what is your opinion 
about:
   ```
           if (line.isEmpty()) {
               return Collections.singletonList("");
           }
   ```



##########
LICENSE:
##########
@@ -234,17 +234,6 @@ for 
drools-drl/drools-drl-parser/src/main/antlr4/org/drools/drl/parser/antlr4/Ja
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
- 
------------------------------------------------------------------------------------
- for 
drools-decisiontables/src/main/java/org/drools/decisiontable/parser/csv/CsvLineParser.java

Review Comment:
   Please, update also 
https://github.com/apache/incubator-kie-drools/blob/main/.rat-excludes, we need 
to remove the entry `CsvLineParsrer`  from there



##########
drools-decisiontables/src/main/java/org/drools/decisiontable/parser/csv/CsvLineParser.java:
##########
@@ -1,150 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.drools.decisiontable.parser.csv;
 
 import java.util.ArrayList;
 import java.util.List;
 
 /**
- * 
- *         a CSV line, with all the normal CSV features.
+ * A simple parser for CSV (Comma-Separated Values) format.
+ * Supports quoted fields, escaped quotes, and custom delimiters.
  */
 public class CsvLineParser {
-    private ICsvParser lineParser;
-
-    public CsvLineParser() {
-        this.lineParser = new CsvParserImpl();
-    }
+    private final char delimiter;
 
     /**
-     * Use the current lineParser implementation to return a CSV line as a List
-     * of cells. (Strings).
+     * Creates a CSV parser with comma as the default delimiter.
      */
-    public List<String> parse(final CharSequence line) {
-        return this.lineParser.parse( line.toString() );
+    public CsvLineParser() {
+        this(',');
     }
 
     /**
-     * This is insurance incase I need to replace it with more complex Csv
-     * handlers in the future.
+     * Creates a CSV parser with a custom delimiter.
+     *
+     * @param delimiter The character to use as field delimiter
      */
-    static interface ICsvParser {
-        public List<String> parse(String line);
+    public CsvLineParser(char delimiter) {
+        this.delimiter = delimiter;

Review Comment:
   Do we want to keep this constructor? I was not able to find its usage, to me 
it seems we use only the default one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to