File tree Expand file tree Collapse file tree
main/java/org/apache/commons/csv
test/java/org/apache/commons/csv Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -82,6 +82,17 @@ public String get(final String name) {
8282 return index != null ? values [index .intValue ()] : null ;
8383 }
8484
85+ /**
86+ * Returns true if this record is consistent, false if not. Currently, the only check is matching the record size to
87+ * the header size. Some programs can export files that fails this test but still produce parsable files.
88+ *
89+ * @return true of this record is valid, false if not
90+ * @see CSVParserTest#org.apache.commons.csv.CSVParserTest.testMappedButNotSetAsOutlook2007ContactExport()
91+ */
92+ public boolean isConsistent () {
93+ return mapping == null ? true : mapping .size () == values .length ;
94+ }
95+
8596 /**
8697 * Checks whether a given column is mapped.
8798 *
Original file line number Diff line number Diff line change @@ -550,6 +550,7 @@ public void testMappedButNotSetAsOutlook2007ContactExport() throws Exception {
550550 assertEquals ("a" , record .get ("A" ));
551551 assertEquals ("b" , record .get ("B" ));
552552 assertEquals ("c" , record .get ("C" ));
553+ assertTrue (record .isConsistent ());
553554
554555 // 1st record
555556 record = records .next ();
@@ -561,6 +562,7 @@ record = records.next();
561562 assertFalse (record .isSet ("C" ));
562563 assertEquals ("1" , record .get ("A" ));
563564 assertEquals ("2" , record .get ("B" ));
565+ assertFalse (record .isConsistent ());
564566
565567 // 2nd record
566568 record = records .next ();
@@ -573,6 +575,7 @@ record = records.next();
573575 assertEquals ("x" , record .get ("A" ));
574576 assertEquals ("y" , record .get ("B" ));
575577 assertEquals ("z" , record .get ("C" ));
578+ assertTrue (record .isConsistent ());
576579
577580 assertFalse (records .hasNext ());
578581 }
You can’t perform that action at this time.
0 commit comments