commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1409455 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/ test/java/org/apache/commons/csv/ test/java/org/apache/commons/csv/perf/
Date Wed, 14 Nov 2012 21:54:17 GMT
Author: ggregory
Date: Wed Nov 14 21:54:16 2012
New Revision: 1409455

URL: http://svn.apache.org/viewvc?rev=1409455&view=rev
Log:
Rename methods that create a builder newBuilder().

Modified:
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatBuilderTest.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java?rev=1409455&r1=1409454&r2=1409455&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java Wed Nov 14
21:54:16 2012
@@ -62,7 +62,7 @@ public class CSVFormat implements Serial
      * </ul>
      */
     public static final CSVFormat RFC4180 =
-            defaults()
+            newBuilder()
             .withIgnoreEmptyLines(false)
             .build();
 
@@ -76,7 +76,7 @@ public class CSVFormat implements Serial
      * </ul>
      */
     public static final CSVFormat DEFAULT = // TODO rename to something more meaningful
-            defaults()
+            newBuilder()
             .build();
 
     /**
@@ -97,13 +97,13 @@ public class CSVFormat implements Serial
      * Note: this is currently the same as RFC4180
      */
     public static final CSVFormat EXCEL =
-            defaults()
+            newBuilder()
             .withIgnoreEmptyLines(false)
             .build();
 
     /** Tab-delimited format, with quote; leading and trailing spaces ignored. */
     public static final CSVFormat TDF =
-            defaults()
+            newBuilder()
             .withDelimiter(TAB)
             .withIgnoreSurroundingSpaces(true)
             .build();
@@ -117,7 +117,7 @@ public class CSVFormat implements Serial
      *      http://dev.mysql.com/doc/refman/5.1/en/load-data.html</a>
      */
     public static final CSVFormat MYSQL =
-            defaults()
+            newBuilder()
             .withDelimiter(TAB)
             .withQuoteChar(null)
             .withEscape(ESCAPE)
@@ -126,13 +126,13 @@ public class CSVFormat implements Serial
             .build();
 
     /**
-     * Factory method for creating CSV formats.
+     * Creates a new CSV format builds.
      * 
      * @param delimiter 
      *            the char used for value separation, must not be a line break character
      * @throws IllegalArgumentException if the delimiter is a line break character
      */
-    public static CSVFormatBuilder newFormat(char delimiter) {
+    public static CSVFormatBuilder newBuilder(char delimiter) {
         return new CSVFormatBuilder(delimiter);
     }
 
@@ -145,7 +145,7 @@ public class CSVFormat implements Serial
      * <li>withLineSeparator(CRLF)</li>
      * </ul>
      */
-    public static CSVFormatBuilder defaults() {
+    public static CSVFormatBuilder newBuilder() {
         return new CSVFormatBuilder(COMMA, DOUBLE_QUOTE, null, null, null, false, true, CRLF,
null);
     }
 

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFileParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFileParserTest.java?rev=1409455&r1=1409454&r2=1409455&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFileParserTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFileParserTest.java Wed
Nov 14 21:54:16 2012
@@ -90,7 +90,7 @@ public class CSVFileParserTest {
         assertTrue(testName+" require 1 param", split.length >= 1);
          // first line starts with csv data file name
         final BufferedReader csvFile = new BufferedReader(new FileReader(new File(BASE, split[0])));
-        CSVFormatBuilder builder = CSVFormat.newFormat(',').withQuoteChar('"');
+        CSVFormatBuilder builder = CSVFormat.newBuilder(',').withQuoteChar('"');
         CSVFormat fmt = builder.build(); 
         boolean checkComments = false;
         for(int i=1; i < split.length; i++) {

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatBuilderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatBuilderTest.java?rev=1409455&r1=1409454&r2=1409455&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatBuilderTest.java
(original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatBuilderTest.java
Wed Nov 14 21:54:16 2012
@@ -45,12 +45,12 @@ public class CSVFormatBuilderTest {
     
     @Test(expected = IllegalArgumentException.class)
     public void testNewFormatLFThrowsException() {
-        CSVFormat.newFormat(LF);
+        CSVFormat.newBuilder(LF);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void testNewFormatCRThrowsException() {
-        CSVFormat.newFormat(CR);
+        CSVFormat.newBuilder(CR);
     }
     
     @Test(expected = IllegalArgumentException.class)
@@ -101,7 +101,7 @@ public class CSVFormatBuilderTest {
     
     @Test(expected = IllegalStateException.class)
     public void testQuotePolicyNoneWithoutEscapeThrowsException() {
-        CSVFormat.newFormat('!').withQuotePolicy(Quote.NONE).build();
+        CSVFormat.newBuilder('!').withQuotePolicy(Quote.NONE).build();
     }
 
     @Test

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java?rev=1409455&r1=1409454&r2=1409455&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java Wed Nov
14 21:54:16 2012
@@ -51,7 +51,7 @@ public class CSVLexerTest {
     @Test
     public void testNextToken1() throws IOException {
         final String code = "abc,def, hijk,  lmnop,   qrst,uv ,wxy   ,z , ,";
-        final Lexer parser = getLexer(code, CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
+        final Lexer parser = getLexer(code, CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
         assertTokenEquals(TOKEN, "abc", parser.nextToken(new Token()));
         assertTokenEquals(TOKEN, "def", parser.nextToken(new Token()));
         assertTokenEquals(TOKEN, "hijk", parser.nextToken(new Token()));
@@ -83,7 +83,7 @@ public class CSVLexerTest {
                 "\n"+
                 "\n"+
                 "# Final comment\n";       // 7
-        final CSVFormat format = CSVFormat.defaults().withCommentStart('#').build();
+        final CSVFormat format = CSVFormat.newBuilder().withCommentStart('#').build();
         assertTrue("Should ignore empty lines", format.getIgnoreEmptyLines());
 
         final Lexer parser = getLexer(code, format);
@@ -126,7 +126,7 @@ public class CSVLexerTest {
                 "\n"+                      // 6b
                 "\n"+                      // 6c
                 "# Final comment\n";       // 7
-        final CSVFormat format = CSVFormat.defaults().withCommentStart('#').withIgnoreEmptyLines(false).build();
+        final CSVFormat format = CSVFormat.newBuilder().withCommentStart('#').withIgnoreEmptyLines(false).build();
         assertFalse("Should not ignore empty lines", format.getIgnoreEmptyLines());
 
         final Lexer parser = getLexer(code, format);
@@ -187,7 +187,7 @@ public class CSVLexerTest {
         *       \,,
         */
         final String code = "a,\\,,b\\\\\n\\,,\\\nc,d\\\r\ne";
-        final CSVFormat format = CSVFormat.defaults().withEscape('\\').withIgnoreEmptyLines(false).build();
+        final CSVFormat format = CSVFormat.newBuilder().withEscape('\\').withIgnoreEmptyLines(false).build();
         assertTrue(format.isEscaping());
         final Lexer parser = getLexer(code, format);
 
@@ -204,7 +204,7 @@ public class CSVLexerTest {
     @Test
     public void testNextToken3BadEscaping() throws IOException {
         final String code = "a,b,c\\";
-        final CSVFormat format = CSVFormat.defaults().withEscape('\\').build();
+        final CSVFormat format = CSVFormat.newBuilder().withEscape('\\').build();
         assertTrue(format.isEscaping());
         final Lexer parser = getLexer(code, format);
 
@@ -226,7 +226,7 @@ public class CSVLexerTest {
         *        a,  " foo " ,b
         */
         final String code = "a,\"foo\",b\na,   \" foo\",b\na,\"foo \"  ,b\na,  \" foo \"
 ,b";
-        final Lexer parser = getLexer(code, CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
+        final Lexer parser = getLexer(code, CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
         assertTokenEquals(TOKEN, "a", parser.nextToken(new Token()));
         assertTokenEquals(TOKEN, "foo", parser.nextToken(new Token()));
         assertTokenEquals(EORECORD, "b", parser.nextToken(new Token()));
@@ -264,7 +264,7 @@ public class CSVLexerTest {
         *       ;;
         */
         final String code = "a;'b and '' more\n'\n!comment;;;;\n;;";
-        final CSVFormat format = CSVFormat.defaults().withDelimiter(';').withQuoteChar('\'').withCommentStart('!').build();
+        final CSVFormat format = CSVFormat.newBuilder().withDelimiter(';').withQuoteChar('\'').withCommentStart('!').build();
         final Lexer parser = getLexer(code, format);
         assertTokenEquals(TOKEN, "a", parser.nextToken(new Token()));
         assertTokenEquals(EORECORD, "b and ' more\n", parser.nextToken(new Token()));

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=1409455&r1=1409454&r2=1409455&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 Wed Nov
14 21:54:16 2012
@@ -71,7 +71,7 @@ public class CSVParserTest {
 
     @Test
     public void testGetLine() throws IOException {
-        final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
+        final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
         for (final String[] re : RESULT) {
             assertArrayEquals(re, parser.nextRecord().values());
         }
@@ -81,7 +81,7 @@ public class CSVParserTest {
 
     @Test
     public void testGetRecords() throws IOException {
-        final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.defaults().withIgnoreSurroundingSpaces(true).build());
+        final CSVParser parser = new CSVParser(new StringReader(CSVINPUT), CSVFormat.newBuilder().withIgnoreSurroundingSpaces(true).build());
         final List<CSVRecord> records = parser.getRecords();
         assertEquals(RESULT.length, records.size());
         assertTrue(records.size() > 0);
@@ -312,7 +312,7 @@ public class CSVParserTest {
         };
 
 
-        final CSVFormat format = CSVFormat.newFormat(',').withQuoteChar('\'').withEscape('/')
+        final CSVFormat format = CSVFormat.newBuilder(',').withQuoteChar('\'').withEscape('/')
                                .withIgnoreEmptyLines(true).withRecordSeparator(CRLF).build();
 
         final CSVParser parser = new CSVParser(code, format);
@@ -342,7 +342,7 @@ public class CSVParserTest {
         };
 
 
-        final CSVFormat format = CSVFormat.newFormat(',').withEscape('/')
+        final CSVFormat format = CSVFormat.newBuilder(',').withEscape('/')
                 .withIgnoreEmptyLines(true).withRecordSeparator(CRLF).build();
 
         final CSVParser parser = new CSVParser(code, format);
@@ -381,7 +381,7 @@ public class CSVParserTest {
                 {"\n", " ", "#"},
         };
 
-        format = CSVFormat.defaults().withCommentStart('#').build();
+        format = CSVFormat.newBuilder().withCommentStart('#').build();
         parser = new CSVParser(code, format);
         records = parser.getRecords();
 
@@ -481,7 +481,7 @@ public class CSVParserTest {
     public void testHeader() throws Exception {
         final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
 
-        final Iterator<CSVRecord> records = CSVFormat.defaults().withHeader().build().parse(in).iterator();
+        final Iterator<CSVRecord> records = CSVFormat.newBuilder().withHeader().build().parse(in).iterator();
 
         for (int i = 0; i < 2; i++) {
             assertTrue(records.hasNext());
@@ -498,7 +498,7 @@ public class CSVParserTest {
     public void testHeaderComment() throws Exception {
         final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
 
-        final Iterator<CSVRecord> records = CSVFormat.defaults().withCommentStart('#').withHeader().build().parse(in).iterator();
+        final Iterator<CSVRecord> records = CSVFormat.newBuilder().withCommentStart('#').withHeader().build().parse(in).iterator();
 
         for (int i = 0; i < 2; i++) {
             assertTrue(records.hasNext());
@@ -515,7 +515,7 @@ public class CSVParserTest {
     public void testProvidedHeader() throws Exception {
         final Reader in = new StringReader("a,b,c\n1,2,3\nx,y,z");
 
-        final Iterator<CSVRecord> records = CSVFormat.defaults().withHeader("A", "B",
"C").build().parse(in).iterator();
+        final Iterator<CSVRecord> records = CSVFormat.newBuilder().withHeader("A",
"B", "C").build().parse(in).iterator();
 
         for (int i = 0; i < 3; i++) {
             assertTrue(records.hasNext());
@@ -536,7 +536,7 @@ public class CSVParserTest {
     public void testMappedButNotSetAsOutlook2007ContactExport() throws Exception {
         final Reader in = new StringReader("a,b,c\n1,2\nx,y,z");
 
-        final Iterator<CSVRecord> records = CSVFormat.defaults().withHeader("A", "B",
"C").build().parse(in).iterator();
+        final Iterator<CSVRecord> records = CSVFormat.newBuilder().withHeader("A",
"B", "C").build().parse(in).iterator();
 
         // header record
         assertTrue(records.hasNext());
@@ -578,7 +578,7 @@ public class CSVParserTest {
     }
 
     public void testGetHeaderMap() throws Exception {
-        final CSVParser parser = new CSVParser("a,b,c\n1,2,3\nx,y,z", CSVFormat.defaults().withHeader("A",
"B", "C").build());
+        final CSVParser parser = new CSVParser("a,b,c\n1,2,3\nx,y,z", CSVFormat.newBuilder().withHeader("A",
"B", "C").build());
         final Map<String, Integer> headerMap = parser.getHeaderMap();
         final Iterator<String> columnNames = headerMap.keySet().iterator();
         // Headers are iterated in column order.
@@ -622,7 +622,7 @@ public class CSVParserTest {
     @Test
     public void testGetRecordWithMultiiLineValues() throws Exception {
         final CSVParser parser = new CSVParser("\"a\r\n1\",\"a\r\n2\"" + CRLF + "\"b\r\n1\",\"b\r\n2\""
+ CRLF + "\"c\r\n1\",\"c\r\n2\"",
-                CSVFormat.defaults().withRecordSeparator(CRLF).build());
+                CSVFormat.newBuilder().withRecordSeparator(CRLF).build());
         CSVRecord record;
         assertEquals(0, parser.getRecordNumber());
         assertEquals(0, parser.getLineNumber());
@@ -654,7 +654,7 @@ public class CSVParserTest {
     }
 
     private void validateRecordNumbers(String lineSeparator) throws IOException {
-        final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator
+ "c", CSVFormat.defaults().withRecordSeparator(lineSeparator).build());
+        final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator
+ "c", CSVFormat.newBuilder().withRecordSeparator(lineSeparator).build());
         CSVRecord record;
         assertEquals(0, parser.getRecordNumber());
         assertNotNull(record = parser.nextRecord());
@@ -671,7 +671,7 @@ public class CSVParserTest {
     }
 
     private void validateLineNumbers(String lineSeparator) throws IOException {
-        final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator
+ "c", CSVFormat.defaults().withRecordSeparator(lineSeparator).build());
+        final CSVParser parser = new CSVParser("a" + lineSeparator + "b" + lineSeparator
+ "c", CSVFormat.newBuilder().withRecordSeparator(lineSeparator).build());
         assertEquals(0, parser.getLineNumber());
         assertNotNull(parser.nextRecord());
         assertEquals(1, parser.getLineNumber());

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java?rev=1409455&r1=1409454&r2=1409455&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVPrinterTest.java Wed
Nov 14 21:54:16 2012
@@ -220,7 +220,7 @@ public class CSVPrinterTest {
     @Test
     public void testMultiLineComment() throws IOException {
         final StringWriter sw = new StringWriter();
-        final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withCommentStart('#').build());
+        final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withCommentStart('#').build());
         printer.printComment("This is a comment\non multiple lines");
 
         assertEquals("# This is a comment" + recordSeparator + "# on multiple lines" + recordSeparator,
sw.toString());
@@ -293,7 +293,7 @@ public class CSVPrinterTest {
     @Test
     public void testQuoteAll() throws IOException {
         final StringWriter sw = new StringWriter();
-        final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withQuotePolicy(Quote.ALL).build());
+        final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuotePolicy(Quote.ALL).build());
         printer.printRecord("a", "b\nc", "d");
         assertEquals("\"a\",\"b\nc\",\"d\"" + recordSeparator, sw.toString());
     }
@@ -301,7 +301,7 @@ public class CSVPrinterTest {
     @Test
     public void testQuoteNonNumeric() throws IOException {
         final StringWriter sw = new StringWriter();
-        final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withQuotePolicy(Quote.NON_NUMERIC).build());
+        final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withQuotePolicy(Quote.NON_NUMERIC).build());
         printer.printRecord("a", "b\nc", Integer.valueOf(1));
         assertEquals("\"a\",\"b\nc\",1" + recordSeparator, sw.toString());
     }
@@ -317,7 +317,7 @@ public class CSVPrinterTest {
     @Test
     public void testSingleLineComment() throws IOException {
         final StringWriter sw = new StringWriter();
-        final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.defaults().withCommentStart('#').build());
+        final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.newBuilder().withCommentStart('#').build());
         printer.printComment("This is a comment");
 
         assertEquals("# This is a comment" + recordSeparator, sw.toString());

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java?rev=1409455&r1=1409454&r2=1409455&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java
(original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java
Wed Nov 14 21:54:16 2012
@@ -66,7 +66,7 @@ public class PerformanceTest {
     }
 
     private long parse(final Reader in, boolean traverseColumns) throws IOException {
-        final CSVFormat format = CSVFormat.defaults().withIgnoreSurroundingSpaces(false).build();
+        final CSVFormat format = CSVFormat.newBuilder().withIgnoreSurroundingSpaces(false).build();
         long recordCount = 0;
         for (final CSVRecord record : format.parse(in)) {
             recordCount++;



Mime
View raw message