diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 3158fcd1..2ead8285 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -355,6 +355,13 @@ public final class CSVFormat implements Serializable { } 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 Serializable { 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 Serializable { 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; diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java index 63a04662..e8e8aa35 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java @@ -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();