Author: [EMAIL PROTECTED]
Date: Fri Oct  3 12:37:10 2008
New Revision: 2748

Added:
   trunk/lib/opencsv-1.8.jar   (contents, props changed)
Removed:
   trunk/lib/darwinsys.jar
Modified:
   trunk/src/ca/sqlpower/architect/profile/output/ProfileCSVFormat.java

Log:
Changed from darwin's CSVExporter to CSVWriter.
Changes were made in order to support this.

-Also removed darwinsys.jar from the library and added
 opencsv-1.8.jar

Added: trunk/lib/opencsv-1.8.jar
==============================================================================
Binary file. No diff available.

Modified: trunk/src/ca/sqlpower/architect/profile/output/ProfileCSVFormat.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/profile/output/ProfileCSVFormat.java (original) +++ trunk/src/ca/sqlpower/architect/profile/output/ProfileCSVFormat.java Fri Oct 3 12:37:10 2008
@@ -22,10 +22,10 @@
 import java.io.PrintWriter;
 import java.text.Format;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Date;
 import java.util.List;

+import au.com.bytecode.opencsv.CSVWriter;
 import ca.sqlpower.architect.SQLColumn;
 import ca.sqlpower.architect.SQLTable;
 import ca.sqlpower.architect.profile.ColumnProfileResult;
@@ -35,8 +35,6 @@
 import ca.sqlpower.swingui.table.DecimalTableCellRenderer;
 import ca.sqlpower.swingui.table.PercentTableCellRenderer;

-import com.darwinsys.csv.CSVExport;
-
 public class ProfileCSVFormat implements ProfileFormat {

     /** The desired CSV column list is published in the ProfileColumn enum.
@@ -48,8 +46,13 @@

         // Print a header
         ProfileColumn[] columns = ProfileColumn.values();
-        out.println(CSVExport.toString(Arrays.asList(columns)));
-
+        String[] columnNames = new String[columns.length];
+        for (int i = 0; i < columns.length; i++) {
+            columnNames[i] = columns[i].toString();
+        }
+        CSVWriter csvWriter = new CSVWriter(out);
+        csvWriter.writeNext(columnNames);
+
         Format dateFormat = new DateTableCellRenderer().getFormat();
         Format decFormat =  new DecimalTableCellRenderer().getFormat();
         Format pctFormat =  new PercentTableCellRenderer().getFormat();
@@ -62,7 +65,7 @@
             SQLColumn c = (SQLColumn) result.getProfiledObject();
             SQLTable t = c.getParentTable();
TableProfileResult tpr = ((ColumnProfileResult)result).getParentResult();
-            List<Object> commonData = new ArrayList<Object>();
+            List<String> commonData = new ArrayList<String>();

             for ( ProfileColumn pc : columns ) {
                 switch(pc) {
@@ -86,13 +89,13 @@
                     commonData.add(dateFormat.format(date));
                     break;
                 case RECORD_COUNT:
-                    commonData.add(tpr.getRowCount());
+                    commonData.add(Integer.toString(tpr.getRowCount()));
                     break;
                 case DATA_TYPE:
-                    commonData.add(c.getType());
+                    commonData.add(Integer.toString(c.getType()));
                     break;
                 case NULL_COUNT:
- commonData.add(((ColumnProfileResult) result).getNullCount()); + commonData.add(Integer.toString(((ColumnProfileResult) result).getNullCount()));
                     break;
                 case PERCENT_NULL:
                     if ( tpr.getRowCount() == 0 )
@@ -102,7 +105,7 @@
((ColumnProfileResult) result).getNullCount() / (double)tpr.getRowCount()));
                     break;
                 case UNIQUE_COUNT:
- commonData.add(((ColumnProfileResult) result).getDistinctValueCount()); + commonData.add(Integer.toString(((ColumnProfileResult) result).getDistinctValueCount()));
                     break;
                 case PERCENT_UNIQUE:
                     if ( tpr.getRowCount() == 0 )
@@ -112,19 +115,29 @@
((ColumnProfileResult) result).getDistinctValueCount() / (double)tpr.getRowCount()));
                     break;
                 case MIN_LENGTH:
- commonData.add(((ColumnProfileResult) result).getMinLength()); + commonData.add(Integer.toString(((ColumnProfileResult) result).getMinLength()));
                     break;
                 case MAX_LENGTH:
- commonData.add(((ColumnProfileResult) result).getMaxLength()); + commonData.add(Integer.toString(((ColumnProfileResult) result).getMaxLength()));
                     break;
                 case AVERAGE_LENGTH:
commonData.add(decFormat.format(((ColumnProfileResult) result).getAvgLength()));
                     break;
                 case MIN_VALUE:
- commonData.add(((ColumnProfileResult) result).getMinValue()); + Object minValue = ((ColumnProfileResult) result).getMinValue();
+                    if (minValue == null) {
+                        commonData.add("");
+                    } else {
+                        commonData.add(minValue.toString());
+                    }
                     break;
                 case MAX_VALUE:
- commonData.add(((ColumnProfileResult) result).getMaxValue()); + Object maxValue = ((ColumnProfileResult) result).getMaxValue();
+                    if (maxValue == null) {
+                        commonData.add("");
+                    } else {
+                        commonData.add(maxValue.toString());
+                    }
                     break;
                 case AVERAGE_VALUE:

@@ -147,8 +160,9 @@

                 }
             }
-            out.println(CSVExport.toString(commonData));
+ csvWriter.writeNext(commonData.toArray(new String[commonData.size()]));
         }
+        csvWriter.close();
         out.close();
     }

Reply via email to