Refactor SSPerformanceTest into a few methods to make it easier to use a profiler

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1742420 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2016-05-05 12:22:16 +00:00
parent f688ed96c6
commit 26de463419

View File

@ -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,6 +79,13 @@ public class SSPerformanceTest {
Row row = sheet.createRow(rowIndexInSheet);
for (int colIndex = 0; colIndex < cols; colIndex++) {
value = populateCell(styles, value, calendar, rowIndex, row, colIndex);
}
rowIndexInSheet++;
}
}
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){
@ -110,11 +128,10 @@ public class SSPerformanceTest {
cell.setCellValue(value++);
break;
}
return value;
}
rowIndexInSheet++;
}
if (saveFile) {
String fileName = type + "_" + rows + "_" + cols + "." + getFileSuffix(args[0]);
private static void saveFile(Workbook workBook, String fileName) {
try {
FileOutputStream out = new FileOutputStream(fileName);
workBook.write(out);
@ -123,9 +140,6 @@ public class SSPerformanceTest {
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) {
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();