commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r1297022 - in /commons/sandbox/csv/trunk/src: main/java/org/apache/commons/csv/CSVFormat.java test/java/org/apache/commons/csv/CSVParserTest.java
Date Mon, 05 Mar 2012 12:12:05 GMT
Author: ebourg
Date: Mon Mar  5 12:12:04 2012
New Revision: 1297022

URL: http://svn.apache.org/viewvc?rev=1297022&view=rev
Log:
Added a convenient parse() method to CSVFormat

Modified:
    commons/sandbox/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
    commons/sandbox/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java

Modified: commons/sandbox/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
URL: http://svn.apache.org/viewvc/commons/sandbox/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java?rev=1297022&r1=1297021&r2=1297022&view=diff
==============================================================================
--- commons/sandbox/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java (original)
+++ commons/sandbox/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java Mon Mar
 5 12:12:04 2012
@@ -17,6 +17,7 @@
 
 package org.apache.commons.csv;
 
+import java.io.Reader;
 import java.io.Serializable;
 
 /**
@@ -198,6 +199,15 @@ public class CSVFormat implements Clonea
         return format;
     }
 
+    /**
+     * Parses the specified content.
+     * 
+     * @param in
+     */
+    public Iterable<String[]> parse(Reader in) {
+        return new CSVParser(in, this);
+    }
+
     protected CSVFormat clone() {
         try {
             return (CSVFormat) super.clone();

Modified: commons/sandbox/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java?rev=1297022&r1=1297021&r2=1297022&view=diff
==============================================================================
--- commons/sandbox/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java (original)
+++ commons/sandbox/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java Mon
Mar  5 12:12:04 2012
@@ -573,22 +573,22 @@ public class CSVParserTest extends TestC
     public void testForEach() {
         List<String[]> records = new ArrayList<String[]>();
         
-        String code = "a,b,c\n1,2,3\nx,y,z";
-        Reader in = new StringReader(code);
+        Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
         
-        for (String[] record : new CSVParser(in)) {
+        for (String[] record : CSVFormat.DEFAULT.parse(in)) {
             records.add(record);
         }
         
         assertEquals(3, records.size());
-        assertTrue(Arrays.equals(new String[] {"a", "b", "c"}, records.get(0)));
+        assertTrue(Arrays.equals(new String[]{"a", "b", "c"}, records.get(0)));
         assertTrue(Arrays.equals(new String[]{"1", "2", "3"}, records.get(1)));
-        assertTrue(Arrays.equals(new String[] {"x", "y", "z"}, records.get(2)));
+        assertTrue(Arrays.equals(new String[]{"x", "y", "z"}, records.get(2)));
     }
 
     public void testIterator() {
-        String code = "a,b,c\n1,2,3\nx,y,z";
-        Iterator<String[]> iterator = new CSVParser(new StringReader(code)).iterator();
+        Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
+        
+        Iterator<String[]> iterator = CSVFormat.DEFAULT.parse(in).iterator();
         
         assertTrue(iterator.hasNext());
         iterator.remove();



Mime
View raw message