Skip to content

Commit 4698a56

Browse files
committed
Add missing fields to hashcode and equals methods
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1592832 13f79535-47bb-0310-9956-ffa450edef68
1 parent 3e8fe99 commit 4698a56

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ public boolean equals(final Object obj) {
355355
} else if (!escape.equals(other.escape)) {
356356
return false;
357357
}
358+
if (nullString == null) {
359+
if (other.nullString != null) {
360+
return false;
361+
}
362+
} else if (!nullString.equals(other.nullString)) {
363+
return false;
364+
}
358365
if (!Arrays.equals(header, other.header)) {
359366
return false;
360367
}
@@ -364,6 +371,9 @@ public boolean equals(final Object obj) {
364371
if (ignoreEmptyLines != other.ignoreEmptyLines) {
365372
return false;
366373
}
374+
if (skipHeaderRecord != other.skipHeaderRecord) {
375+
return false;
376+
}
367377
if (recordSeparator == null) {
368378
if (other.recordSeparator != null) {
369379
return false;
@@ -512,8 +522,10 @@ public int hashCode()
512522
result = prime * result + ((quoteChar == null) ? 0 : quoteChar.hashCode());
513523
result = prime * result + ((commentStart == null) ? 0 : commentStart.hashCode());
514524
result = prime * result + ((escape == null) ? 0 : escape.hashCode());
525+
result = prime * result + ((nullString == null) ? 0 : nullString.hashCode());
515526
result = prime * result + (ignoreSurroundingSpaces ? 1231 : 1237);
516527
result = prime * result + (ignoreEmptyLines ? 1231 : 1237);
528+
result = prime * result + (skipHeaderRecord ? 1231 : 1237);
517529
result = prime * result + ((recordSeparator == null) ? 0 : recordSeparator.hashCode());
518530
result = prime * result + Arrays.hashCode(header);
519531
return result;

src/test/java/org/apache/commons/csv/CSVFormatTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,41 @@ public void testEqualsRecordSeparator() {
196196
assertNotEquals(right, left);
197197
}
198198

199+
@Test
200+
public void testEqualsNullString() {
201+
final CSVFormat right = CSVFormat.newFormat('\'')
202+
.withRecordSeparator('*')
203+
.withCommentStart('#')
204+
.withEscape('+')
205+
.withIgnoreEmptyLines(true)
206+
.withIgnoreSurroundingSpaces(true)
207+
.withQuoteChar('"')
208+
.withQuotePolicy(Quote.ALL)
209+
.withNullString("null");
210+
final CSVFormat left = right
211+
.withNullString("---");
212+
213+
assertNotEquals(right, left);
214+
}
215+
216+
@Test
217+
public void testEqualsSkipHeaderRecord() {
218+
final CSVFormat right = CSVFormat.newFormat('\'')
219+
.withRecordSeparator('*')
220+
.withCommentStart('#')
221+
.withEscape('+')
222+
.withIgnoreEmptyLines(true)
223+
.withIgnoreSurroundingSpaces(true)
224+
.withQuoteChar('"')
225+
.withQuotePolicy(Quote.ALL)
226+
.withNullString("null")
227+
.withSkipHeaderRecord(true);
228+
final CSVFormat left = right
229+
.withSkipHeaderRecord(false);
230+
231+
assertNotEquals(right, left);
232+
}
233+
199234
@Test(expected = IllegalStateException.class)
200235
public void testEscapeSameAsCommentStartThrowsException() {
201236
CSVFormat.DEFAULT.withEscape('!').withCommentStart('!').validate();

0 commit comments

Comments
 (0)