You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2015/08/11 00:11:24 UTC

svn commit: r1695178 - in /commons/proper/csv/trunk/src: changes/changes.xml main/java/org/apache/commons/csv/CSVFormat.java test/java/org/apache/commons/csv/CSVFormatPredefinedTest.java

Author: ggregory
Date: Mon Aug 10 22:11:24 2015
New Revision: 1695178

URL: http://svn.apache.org/r1695178
Log:
[CSV-157] Add enum CSVFormat.Predefined that contains the default CSVFormat values.

Added:
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatPredefinedTest.java
Modified:
    commons/proper/csv/trunk/src/changes/changes.xml
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVFormat.java

Modified: commons/proper/csv/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/changes/changes.xml?rev=1695178&r1=1695177&r2=1695178&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/changes/changes.xml (original)
+++ commons/proper/csv/trunk/src/changes/changes.xml Mon Aug 10 22:11:24 2015
@@ -38,9 +38,10 @@
     <title>Release Notes</title>
   </properties>
   <body>
-    <release version="1.1.1" date="20??-MM-DD" description="Feature and bug fix release">
+    <release version="1.2" date="2015-MM-DD" description="Feature and bug fix release">
       <action issue="CSV-145" type="fix" dev="ggregory" due-to="Frank Ulbricht">CSVFormat.with* methods clear the header comments</action>
       <action issue="CSV-156" type="fix" dev="ggregory" due-to="Jason Steenstra-Pickens">Incorrect Javadoc on QuoteMode.NONE</action>
+      <action issue="CSV-157" type="add" dev="ggregory">Add enum CSVFormat.Predefined that contains the default CSVFormat values.</action>
     </release>
     <release version="1.1" date="2014-11-16" description="Feature and bug fix release">
       <action issue="CSV-140" type="fix" dev="ggregory" due-to="Damjan Jovanovic">QuoteMode.NON_NUMERIC doesn't work with CSVPrinter.printRecords(ResultSet)</action>

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=1695178&r1=1695177&r2=1695178&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 Mon Aug 10 22:11:24 2015
@@ -147,6 +147,54 @@ import java.util.Set;
  */
 public final class CSVFormat implements Serializable {
 
+    /**
+     * Predefines formats.
+     * 
+     * @since 1.2
+     */
+    public static enum Predefined {
+
+        /**
+         * @see CSVFormat#DEFAULT.
+         */
+        Default(CSVFormat.DEFAULT), 
+
+        /**
+         * @see CSVFormat#EXCEL.
+         */
+        Excel(CSVFormat.EXCEL), 
+
+        /**
+         * @see CSVFormat#MYSQL.
+         */
+        MySQL(CSVFormat.MYSQL), 
+
+        /**
+         * @see CSVFormat#RFC4180.
+         */
+        RFC4180(CSVFormat.RFC4180),
+
+        /**
+         * @see CSVFormat#TDF.
+         */
+        TDF(CSVFormat.TDF);
+
+        private final CSVFormat format;
+
+        private Predefined(CSVFormat format) {
+            this.format = format;
+        }
+        
+        /**
+         * Gets the format.
+         * 
+         * @return the format.
+         */
+        public CSVFormat getFormat() {
+            return format;
+        }
+    };
+    
     private static final long serialVersionUID = 1L;
 
     private final char delimiter;
@@ -175,6 +223,7 @@ public final class CSVFormat implements
      * <li>withRecordSeparator("\r\n")</li>
      * <li>withIgnoreEmptyLines(true)</li>
      * </ul>
+     * @see Predefined#Default
      */
     public static final CSVFormat DEFAULT = new CSVFormat(COMMA, DOUBLE_QUOTE_CHAR, null, null, null, false, true,
             CRLF, null, null, null, false, false);
@@ -191,6 +240,7 @@ public final class CSVFormat implements
      * <li>withRecordSeparator("\r\n")</li>
      * <li>withIgnoreEmptyLines(false)</li>
      * </ul>
+     * @see Predefined#RFC4180
      */
     public static final CSVFormat RFC4180 = DEFAULT.withIgnoreEmptyLines(false);
 
@@ -220,6 +270,7 @@ public final class CSVFormat implements
      * Note: this is currently like {@link #RFC4180} plus {@link #withAllowMissingColumnNames(boolean)
      * withAllowMissingColumnNames(true)}.
      * </p>
+     * @see Predefined#Excel
      */
     public static final CSVFormat EXCEL = DEFAULT.withIgnoreEmptyLines(false).withAllowMissingColumnNames();
 
@@ -235,6 +286,7 @@ public final class CSVFormat implements
      * <li>withRecordSeparator("\r\n")</li>
      * <li>withIgnoreSurroundingSpaces(true)</li>
      * </ul>
+     * @see Predefined#TDF
      */
     public static final CSVFormat TDF = DEFAULT.withDelimiter(TAB).withIgnoreSurroundingSpaces();
 
@@ -257,6 +309,7 @@ public final class CSVFormat implements
      * <li>withEscape('\\')</li>
      * </ul>
      *
+     * @see Predefined#MySQL
      * @see <a href="http://dev.mysql.com/doc/refman/5.1/en/load-data.html">
      *      http://dev.mysql.com/doc/refman/5.1/en/load-data.html</a>
      */

Added: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatPredefinedTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatPredefinedTest.java?rev=1695178&view=auto
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatPredefinedTest.java (added)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVFormatPredefinedTest.java Mon Aug 10 22:11:24 2015
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.csv;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests {@link CSVFormat.Predefined}.
+ */
+public class CSVFormatPredefinedTest {
+
+    private void test(final CSVFormat format, final String enumName) {
+        Assert.assertEquals(format, CSVFormat.Predefined.valueOf(enumName).getFormat());
+    }
+
+    @Test
+    public void testDefault() {
+        test(CSVFormat.DEFAULT, "Default");
+    }
+
+    @Test
+    public void testExcel() {
+        test(CSVFormat.EXCEL, "Excel");
+    }
+
+    @Test
+    public void testMySQL() {
+        test(CSVFormat.MYSQL, "MySQL");
+    }
+
+    @Test
+    public void testRFC4180() {
+        test(CSVFormat.RFC4180, "RFC4180");
+    }
+
+    @Test
+    public void testTDF() {
+        test(CSVFormat.TDF, "TDF");
+    }
+}