This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git

commit d1601d3fec319419c6548bdc5719f35b1928403f
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Jul 3 09:13:51 2021 -0400

    Organize imports, simpler arrays, simpler if/else.
---
 .../java/org/apache/commons/csv/CSVFormat.java     | 22 +++++++++-------------
 .../java/org/apache/commons/csv/Constants.java     |  2 +-
 .../java/org/apache/commons/csv/CSVFormatTest.java | 11 +++++------
 .../org/apache/commons/csv/CSVPrinterTest.java     |  2 +-
 .../java/org/apache/commons/csv/LexerTest.java     |  3 ++-
 .../org/apache/commons/csv/TokenMatchersTest.java  |  2 +-
 .../apache/commons/csv/issues/JiraCsv211Test.java  | 12 ++++++------
 .../apache/commons/csv/issues/JiraCsv248Test.java  |  6 +++---
 8 files changed, 28 insertions(+), 32 deletions(-)

diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java 
b/src/main/java/org/apache/commons/csv/CSVFormat.java
index 9cfd6b8..a95cccf 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -1183,22 +1183,18 @@ public final class CSVFormat implements Serializable {
             // https://issues.apache.org/jira/browse/CSV-203
             if (null == nullString) {
                 charSequence = EMPTY;
+            } else if (QuoteMode.ALL == quoteMode) {
+                charSequence = quotedNullString;
             } else {
-                if (QuoteMode.ALL == quoteMode) {
-                    charSequence = quotedNullString;
-                } else {
-                    charSequence = nullString;
-                }
+                charSequence = nullString;
             }
+        } else if (value instanceof CharSequence) {
+            charSequence = (CharSequence) value;
+        } else if (value instanceof Reader) {
+            print((Reader) value, out, newRecord);
+            return;
         } else {
-            if (value instanceof CharSequence) {
-                charSequence = (CharSequence) value;
-            } else if (value instanceof Reader) {
-                print((Reader) value, out, newRecord);
-                return;
-            } else {
-                charSequence = value.toString();
-            }
+            charSequence = value.toString();
         }
         charSequence = getTrim() ? trim(charSequence) : charSequence;
         print(value, charSequence, out, newRecord);
diff --git a/src/main/java/org/apache/commons/csv/Constants.java 
b/src/main/java/org/apache/commons/csv/Constants.java
index 10c2006..a4d4d67 100644
--- a/src/main/java/org/apache/commons/csv/Constants.java
+++ b/src/main/java/org/apache/commons/csv/Constants.java
@@ -79,6 +79,6 @@ final class Constants {
     /** ASCII unit separator */
     static final char US = 31;
 
-    static final String[] EMPTY_STRING_ARRAY = new String[0];
+    static final String[] EMPTY_STRING_ARRAY = {};
 
 }
diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java 
b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
index d9de99f..2dddaa3 100644
--- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
@@ -21,7 +21,6 @@ import static org.apache.commons.csv.CSVFormat.RFC4180;
 import static org.apache.commons.csv.Constants.CR;
 import static org.apache.commons.csv.Constants.CRLF;
 import static org.apache.commons.csv.Constants.LF;
-
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -34,10 +33,10 @@ import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Reader;
-import java.io.IOException;
 import java.io.StringReader;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
@@ -175,7 +174,7 @@ public class CSVFormatTest {
                            assertNotEquals(name, type, a, b);
                        } else if ("java.lang.Character".equals(type)){
                            final Object a = method.invoke(CSVFormat.DEFAULT, 
new Object[] {null});
-                           final Object b = method.invoke(CSVFormat.DEFAULT, 
new Character('d'));
+                           final Object b = method.invoke(CSVFormat.DEFAULT, 
Character.valueOf('d'));
                            assertNotEquals(name, type, a, b);
                        } else if ("java.lang.String".equals(type)){
                            final Object a = method.invoke(CSVFormat.DEFAULT, 
new Object[] {null});
@@ -538,7 +537,7 @@ public class CSVFormatTest {
         // Cannot assume that callers won't use different Character objects
         assertThrows(
                 IllegalArgumentException.class,
-                () -> 
CSVFormat.DEFAULT.withEscape(Character.valueOf('!')).withCommentMarker(new 
Character('!')));
+                () -> 
CSVFormat.DEFAULT.withEscape(Character.valueOf('!')).withCommentMarker(Character.valueOf('!')));
     }
 
     @Test
@@ -561,7 +560,7 @@ public class CSVFormatTest {
 
     @Test
     public void testGetHeader() {
-        final String[] header = new String[]{"one", "two", "three"};
+        final String[] header = {"one", "two", "three"};
         final CSVFormat formatWithHeader = 
CSVFormat.DEFAULT.withHeader(header);
         // getHeader() makes a copy of the header array.
         final String[] headerCopy = formatWithHeader.getHeader();
@@ -940,7 +939,7 @@ public class CSVFormatTest {
 
     @Test
     public void testWithHeader() {
-        final String[] header = new String[]{"one", "two", "three"};
+        final String[] header = {"one", "two", "three"};
         // withHeader() makes a copy of the header array.
         final CSVFormat formatWithHeader = 
CSVFormat.DEFAULT.withHeader(header);
         assertArrayEquals(header, formatWithHeader.getHeader());
diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java 
b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
index 16712ae..4d60a3b 100644
--- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
@@ -1360,7 +1360,7 @@ public class CSVPrinterTest {
 
     @Test
     public void testPrintRecordsWithCSVRecord() throws IOException {
-        final String[] values = new String[] {"A", "B", "C"};
+        final String[] values = {"A", "B", "C"};
         final String rowData = StringUtils.join(values, ',');
         final CharArrayWriter charArrayWriter = new CharArrayWriter(0);
         try (final CSVParser parser = CSVFormat.DEFAULT.parse(new 
StringReader(rowData));
diff --git a/src/test/java/org/apache/commons/csv/LexerTest.java 
b/src/test/java/org/apache/commons/csv/LexerTest.java
index d2dea02..b289773 100644
--- a/src/test/java/org/apache/commons/csv/LexerTest.java
+++ b/src/test/java/org/apache/commons/csv/LexerTest.java
@@ -29,10 +29,11 @@ import static org.apache.commons.csv.Token.Type.TOKEN;
 import static org.apache.commons.csv.TokenMatchers.hasContent;
 import static org.apache.commons.csv.TokenMatchers.matches;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+
 import java.io.IOException;
 import java.io.StringReader;
 
diff --git a/src/test/java/org/apache/commons/csv/TokenMatchersTest.java 
b/src/test/java/org/apache/commons/csv/TokenMatchersTest.java
index 3123e43..e8a115d 100644
--- a/src/test/java/org/apache/commons/csv/TokenMatchersTest.java
+++ b/src/test/java/org/apache/commons/csv/TokenMatchersTest.java
@@ -20,9 +20,9 @@ import static org.apache.commons.csv.TokenMatchers.hasContent;
 import static org.apache.commons.csv.TokenMatchers.hasType;
 import static org.apache.commons.csv.TokenMatchers.isReady;
 import static org.apache.commons.csv.TokenMatchers.matches;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java 
b/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java
index d341c25..fc44261 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java
@@ -16,21 +16,21 @@
  */
 package org.apache.commons.csv.issues;
 
-import org.apache.commons.csv.CSVFormat;
-import org.apache.commons.csv.CSVParser;
-import org.apache.commons.csv.CSVRecord;
-import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.io.IOException;
 import java.io.StringReader;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.apache.commons.csv.CSVFormat;
+import org.apache.commons.csv.CSVParser;
+import org.apache.commons.csv.CSVRecord;
+import org.junit.jupiter.api.Test;
 
 public class JiraCsv211Test {
 
     @Test
     public void testJiraCsv211Format() throws IOException {
-        final String[] values = new String[] { "1", "Jane Doe", "USA", "" };
+        final String[] values = { "1", "Jane Doe", "USA", "" };
 
         final CSVFormat printFormat = 
CSVFormat.DEFAULT.withDelimiter('\t').withHeader("ID", "Name", "Country", 
"Age");
         final String formatted = printFormat.format(values);
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java 
b/src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java
index 7b53b75..d19fe44 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java
@@ -22,13 +22,13 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import org.apache.commons.csv.CSVRecord;
-import org.junit.jupiter.api.Test;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
 
+import org.apache.commons.csv.CSVRecord;
+import org.junit.jupiter.api.Test;
+
 public class JiraCsv248Test {
     /**
      * Test deserialisation of a CSVRecord created using version 1.6.

Reply via email to