You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2014/05/06 20:32:38 UTC

svn commit: r1592832 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CSVFormat.java test/java/org/apache/commons/csv/CSVFormatTest.java

Author: britter
Date: Tue May  6 18:32:38 2014
New Revision: 1592832

URL: http://svn.apache.org/r1592832
Log:
Add missing fields to hashcode and equals methods

Modified:
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java?rev=1592832&r1=1592831&r2=1592832&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java Tue May  6 18:32:38 2014
@@ -355,6 +355,13 @@ public final class CSVFormat implements 
         } else if (!escape.equals(other.escape)) {
             return false;
         }
+        if (nullString == null) {
+            if (other.nullString != null) {
+                return false;
+            }
+        } else if (!nullString.equals(other.nullString)) {
+            return false;
+        }
         if (!Arrays.equals(header, other.header)) {
             return false;
         }
@@ -364,6 +371,9 @@ public final class CSVFormat implements 
         if (ignoreEmptyLines != other.ignoreEmptyLines) {
             return false;
         }
+        if (skipHeaderRecord != other.skipHeaderRecord) {
+            return false;
+        }
         if (recordSeparator == null) {
             if (other.recordSeparator != null) {
                 return false;
@@ -512,8 +522,10 @@ public final class CSVFormat implements 
         result = prime * result + ((quoteChar == null) ? 0 : quoteChar.hashCode());
         result = prime * result + ((commentStart == null) ? 0 : commentStart.hashCode());
         result = prime * result + ((escape == null) ? 0 : escape.hashCode());
+        result = prime * result + ((nullString == null) ? 0 : nullString.hashCode());
         result = prime * result + (ignoreSurroundingSpaces ? 1231 : 1237);
         result = prime * result + (ignoreEmptyLines ? 1231 : 1237);
+        result = prime * result + (skipHeaderRecord ? 1231 : 1237);
         result = prime * result + ((recordSeparator == null) ? 0 : recordSeparator.hashCode());
         result = prime * result + Arrays.hashCode(header);
         return result;

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java?rev=1592832&r1=1592831&r2=1592832&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatTest.java Tue May  6 18:32:38 2014
@@ -196,6 +196,41 @@ public class CSVFormatTest {
         assertNotEquals(right, left);
     }
 
+    @Test
+    public void testEqualsNullString() {
+        final CSVFormat right = CSVFormat.newFormat('\'')
+                .withRecordSeparator('*')
+                .withCommentStart('#')
+                .withEscape('+')
+                .withIgnoreEmptyLines(true)
+                .withIgnoreSurroundingSpaces(true)
+                .withQuoteChar('"')
+                .withQuotePolicy(Quote.ALL)
+                .withNullString("null");
+        final CSVFormat left = right
+                .withNullString("---");
+
+        assertNotEquals(right, left);
+    }
+
+    @Test
+    public void testEqualsSkipHeaderRecord() {
+        final CSVFormat right = CSVFormat.newFormat('\'')
+                .withRecordSeparator('*')
+                .withCommentStart('#')
+                .withEscape('+')
+                .withIgnoreEmptyLines(true)
+                .withIgnoreSurroundingSpaces(true)
+                .withQuoteChar('"')
+                .withQuotePolicy(Quote.ALL)
+                .withNullString("null")
+                .withSkipHeaderRecord(true);
+        final CSVFormat left = right
+                .withSkipHeaderRecord(false);
+
+        assertNotEquals(right, left);
+    }
+
     @Test(expected = IllegalStateException.class)
     public void testEscapeSameAsCommentStartThrowsException() {
         CSVFormat.DEFAULT.withEscape('!').withCommentStart('!').validate();