commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1462110 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CSVRecord.java test/java/org/apache/commons/csv/CSVParserTest.java
Date Thu, 28 Mar 2013 14:23:56 GMT
Author: ggregory
Date: Thu Mar 28 14:23:56 2013
New Revision: 1462110

URL: http://svn.apache.org/r1462110
Log:
[CSV-96] CSVRecord does not verify that the length of the header mapping matches the number
of values.

Modified:
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java?rev=1462110&r1=1462109&r2=1462110&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java Thu Mar 28
14:23:56 2013
@@ -83,6 +83,17 @@ public class CSVRecord implements Serial
     }
 
     /**
+     * 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.
      *
      * @param name

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java?rev=1462110&r1=1462109&r2=1462110&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java Thu Mar
28 14:23:56 2013
@@ -550,6 +550,7 @@ public class CSVParserTest {
         assertEquals("a", record.get("A"));
         assertEquals("b", record.get("B"));
         assertEquals("c", record.get("C"));
+        assertTrue(record.isConsistent());
 
         // 1st record
         record = records.next();
@@ -561,6 +562,7 @@ public class CSVParserTest {
         assertFalse(record.isSet("C"));
         assertEquals("1", record.get("A"));
         assertEquals("2", record.get("B"));
+        assertFalse(record.isConsistent());
 
         // 2nd record
         record = records.next();
@@ -573,6 +575,7 @@ public class CSVParserTest {
         assertEquals("x", record.get("A"));
         assertEquals("y", record.get("B"));
         assertEquals("z", record.get("C"));
+        assertTrue(record.isConsistent());
 
         assertFalse(records.hasNext());
     }



Mime
View raw message