You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2016/05/05 12:22:16 UTC

svn commit: r1742420 - /poi/trunk/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java

Author: centic
Date: Thu May  5 12:22:16 2016
New Revision: 1742420

URL: http://svn.apache.org/viewvc?rev=1742420&view=rev
Log:
Refactor SSPerformanceTest into a few methods to make it easier to use a profiler

Modified:
    poi/trunk/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java

Modified: poi/trunk/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java?rev=1742420&r1=1742419&r2=1742420&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java Thu May  5 12:22:16 2016
@@ -44,6 +44,17 @@ public class SSPerformanceTest {
         int cols = parseInt(args[2], "Failed to parse cols value as integer");
         boolean saveFile = parseInt(args[3], "Failed to parse saveFile value as integer") != 0;
 
+        addContent(workBook, isHType, rows, cols);
+
+        if (saveFile) {
+            String fileName = type + "_" + rows + "_" + cols + "." + getFileSuffix(args[0]);
+            saveFile(workBook, fileName);
+        }
+        long timeFinished = System.currentTimeMillis();
+        System.out.println("Elapsed " + (timeFinished-timeStarted)/1000 + " seconds");
+    }
+
+    private static void addContent(Workbook workBook, boolean isHType, int rows, int cols) {
         Map<String, CellStyle> styles = createStyles(workBook);
 
         Sheet sheet = workBook.createSheet("Main Sheet");
@@ -68,63 +79,66 @@ public class SSPerformanceTest {
 
             Row row = sheet.createRow(rowIndexInSheet);
             for (int colIndex = 0; colIndex < cols; colIndex++) {
-                Cell cell = row.createCell(colIndex);
-                String address = new CellReference(cell).formatAsString();
-                switch (colIndex){
-                    case 0:
-                        // column A: default number format
-                        cell.setCellValue(value++);
-                        break;
-                    case 1:
-                        // column B: #,##0
-                        cell.setCellValue(value++);
-                        cell.setCellStyle(styles.get("#,##0.00"));
-                        break;
-                    case 2:
-                        // column C: $#,##0.00
-                        cell.setCellValue(value++);
-                        cell.setCellStyle(styles.get("$#,##0.00"));
-                        break;
-                    case 3:
-                        // column D: red bold text on yellow background
-                        cell.setCellValue(address);
-                        cell.setCellStyle(styles.get("red-bold"));
-                        break;
-                    case 4:
-                        // column E: boolean
-                        // TODO booleans are shown as 1/0 instead of TRUE/FALSE
-                        cell.setCellValue(rowIndex % 2 == 0);
-                        break;
-                    case 5:
-                        // column F:  date / time
-                        cell.setCellValue(calendar);
-                        cell.setCellStyle(styles.get("m/d/yyyy"));
-                        calendar.roll(Calendar.DAY_OF_YEAR, -1);
-                        break;
-                    case 6:
-                        // column F: formula
-                        // TODO formulas are not yet supported  in SXSSF
-                        //cell.setCellFormula("SUM(A" + (rowIndex+1) + ":E" + (rowIndex+1)+ ")");
-                        //break;
-                    default:
-                        cell.setCellValue(value++);
-                        break;
-                }
+                value = populateCell(styles, value, calendar, rowIndex, row, colIndex);
             }
             rowIndexInSheet++;
         }
-        if (saveFile) {
-            String fileName = type + "_" + rows + "_" + cols + "." + getFileSuffix(args[0]);
-            try {
-                FileOutputStream out = new FileOutputStream(fileName);
-                workBook.write(out);
-                out.close();
-            } catch (IOException ioe) {
-                System.err.println("Error: failed to write to file \"" + fileName + "\", reason=" + ioe.getMessage());
-            }
+    }
+
+    private static double populateCell(Map<String, CellStyle> styles, double value, Calendar calendar, int rowIndex, Row row, int colIndex) {
+        Cell cell = row.createCell(colIndex);
+        String address = new CellReference(cell).formatAsString();
+        switch (colIndex){
+            case 0:
+                // column A: default number format
+                cell.setCellValue(value++);
+                break;
+            case 1:
+                // column B: #,##0
+                cell.setCellValue(value++);
+                cell.setCellStyle(styles.get("#,##0.00"));
+                break;
+            case 2:
+                // column C: $#,##0.00
+                cell.setCellValue(value++);
+                cell.setCellStyle(styles.get("$#,##0.00"));
+                break;
+            case 3:
+                // column D: red bold text on yellow background
+                cell.setCellValue(address);
+                cell.setCellStyle(styles.get("red-bold"));
+                break;
+            case 4:
+                // column E: boolean
+                // TODO booleans are shown as 1/0 instead of TRUE/FALSE
+                cell.setCellValue(rowIndex % 2 == 0);
+                break;
+            case 5:
+                // column F:  date / time
+                cell.setCellValue(calendar);
+                cell.setCellStyle(styles.get("m/d/yyyy"));
+                calendar.roll(Calendar.DAY_OF_YEAR, -1);
+                break;
+            case 6:
+                // column F: formula
+                // TODO formulas are not yet supported  in SXSSF
+                //cell.setCellFormula("SUM(A" + (rowIndex+1) + ":E" + (rowIndex+1)+ ")");
+                //break;
+            default:
+                cell.setCellValue(value++);
+                break;
+        }
+        return value;
+    }
+
+    private static void saveFile(Workbook workBook, String fileName) {
+        try {
+            FileOutputStream out = new FileOutputStream(fileName);
+            workBook.write(out);
+            out.close();
+        } catch (IOException ioe) {
+            System.err.println("Error: failed to write to file \"" + fileName + "\", reason=" + ioe.getMessage());
         }
-        long timeFinished = System.currentTimeMillis();
-        System.out.println("Elapsed " + (timeFinished-timeStarted)/1000 + " seconds");
     }
 
     static Map<String, CellStyle> createStyles(Workbook wb) {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org