[CSV-96] CSVRecord does not verify that the length of the header mapping matches the number of values.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1462110 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
08f02a086c
commit
8f436552ae
|
@ -82,6 +82,17 @@ public class CSVRecord implements Serializable, Iterable<String> {
|
||||||
return index != null ? values[index.intValue()] : null;
|
return index != null ? values[index.intValue()] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this record is consistent, false if not. Currently, the only check is matching the record size to
|
||||||
|
* the header size. Some programs can export files that fails this test but still produce parsable files.
|
||||||
|
*
|
||||||
|
* @return true of this record is valid, false if not
|
||||||
|
* @see CSVParserTest#org.apache.commons.csv.CSVParserTest.testMappedButNotSetAsOutlook2007ContactExport()
|
||||||
|
*/
|
||||||
|
public boolean isConsistent() {
|
||||||
|
return mapping == null ? true : mapping.size() == values.length;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a given column is mapped.
|
* Checks whether a given column is mapped.
|
||||||
*
|
*
|
||||||
|
|
|
@ -550,6 +550,7 @@ public class CSVParserTest {
|
||||||
assertEquals("a", record.get("A"));
|
assertEquals("a", record.get("A"));
|
||||||
assertEquals("b", record.get("B"));
|
assertEquals("b", record.get("B"));
|
||||||
assertEquals("c", record.get("C"));
|
assertEquals("c", record.get("C"));
|
||||||
|
assertTrue(record.isConsistent());
|
||||||
|
|
||||||
// 1st record
|
// 1st record
|
||||||
record = records.next();
|
record = records.next();
|
||||||
|
@ -561,6 +562,7 @@ public class CSVParserTest {
|
||||||
assertFalse(record.isSet("C"));
|
assertFalse(record.isSet("C"));
|
||||||
assertEquals("1", record.get("A"));
|
assertEquals("1", record.get("A"));
|
||||||
assertEquals("2", record.get("B"));
|
assertEquals("2", record.get("B"));
|
||||||
|
assertFalse(record.isConsistent());
|
||||||
|
|
||||||
// 2nd record
|
// 2nd record
|
||||||
record = records.next();
|
record = records.next();
|
||||||
|
@ -573,6 +575,7 @@ public class CSVParserTest {
|
||||||
assertEquals("x", record.get("A"));
|
assertEquals("x", record.get("A"));
|
||||||
assertEquals("y", record.get("B"));
|
assertEquals("y", record.get("B"));
|
||||||
assertEquals("z", record.get("C"));
|
assertEquals("z", record.get("C"));
|
||||||
|
assertTrue(record.isConsistent());
|
||||||
|
|
||||||
assertFalse(records.hasNext());
|
assertFalse(records.hasNext());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue