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
This commit is contained in:
Benedikt Ritter 2014-05-06 18:32:38 +00:00
parent 3e8fe990dd
commit 4698a563dc
2 changed files with 47 additions and 0 deletions

View File

@ -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;

View File

@ -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();