]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.excel.poi/src/org/simantics/excel/poi/parser/CellDataResolverBase.java
CellDataResolverBase causes an exception when processing empty rows.
[simantics/interop.git] / org.simantics.excel.poi / src / org / simantics / excel / poi / parser / CellDataResolverBase.java
index 5a78735ded0099f60e1b965e0c29f0ed7352b4cc..99412bbab884d385dadf58088f49d009950ffa70 100644 (file)
@@ -1,88 +1,97 @@
-package org.simantics.excel.poi.parser;\r
-\r
-import org.apache.poi.ss.usermodel.Cell;\r
-import org.apache.poi.ss.usermodel.Row;\r
-\r
-public abstract class CellDataResolverBase<T> implements DataResolver<T> {\r
-       \r
-               \r
-       protected Double getCellNumericValue(Cell cell) {\r
-               if (cell == null)\r
-                       return null;\r
-               switch (cell.getCellType()) {\r
-               case Cell.CELL_TYPE_BLANK:\r
-                       return null;\r
-               case Cell.CELL_TYPE_BOOLEAN:\r
-                       return null;\r
-               case Cell.CELL_TYPE_ERROR:\r
-                       return null;\r
-               case Cell.CELL_TYPE_FORMULA:\r
-                       return null;\r
-               case Cell.CELL_TYPE_NUMERIC:\r
-                       return cell.getNumericCellValue();\r
-               case Cell.CELL_TYPE_STRING:\r
-                       return null;\r
-                       \r
-               }\r
-               throw new RuntimeException();\r
-       }\r
-       \r
-       protected String getCellStringValue(Cell cell) {\r
-               if (cell == null)\r
-                       return null;\r
-               switch (cell.getCellType()) {\r
-               case Cell.CELL_TYPE_BLANK:\r
-                       return null;\r
-               case Cell.CELL_TYPE_BOOLEAN:\r
-                       return Boolean.toString(cell.getBooleanCellValue());\r
-               case Cell.CELL_TYPE_ERROR:\r
-                       return null;\r
-               case Cell.CELL_TYPE_FORMULA:\r
-                       return null;\r
-               case Cell.CELL_TYPE_NUMERIC:\r
-                       return Double.toString(cell.getNumericCellValue());\r
-               case Cell.CELL_TYPE_STRING:\r
-                       return cell.getStringCellValue();\r
-                       \r
-               }\r
-               throw new RuntimeException();\r
-       }\r
-       \r
-       protected Boolean getCellBooleanValue(Cell cell) {\r
-               if (cell == null)\r
-                       return null;\r
-               switch (cell.getCellType()) {\r
-               case Cell.CELL_TYPE_BLANK:\r
-                       return null;\r
-               case Cell.CELL_TYPE_BOOLEAN:\r
-                       return cell.getBooleanCellValue();\r
-               case Cell.CELL_TYPE_ERROR:\r
-                       return null;\r
-               case Cell.CELL_TYPE_FORMULA:\r
-                       return null;\r
-               case Cell.CELL_TYPE_NUMERIC:\r
-                       return null;\r
-               case Cell.CELL_TYPE_STRING:\r
-                       String value = cell.getStringCellValue();\r
-                       if ("true".equalsIgnoreCase(value))\r
-                               return true;\r
-                       if ("1".equalsIgnoreCase(value))\r
-                               return true;\r
-                       return false;           \r
-               }\r
-               throw new RuntimeException();\r
-       }\r
-       \r
-       protected Cell getCell(Row row, int colIndex) {\r
-               for (short i = row.getFirstCellNum(); i <= row.getLastCellNum(); i++) {\r
-                       Cell c = row.getCell(i);\r
-                       if (c == null)\r
-                               continue;\r
-                       if (c.getColumnIndex() == colIndex)\r
-                               return c;\r
-                       \r
-               }\r
-               return null;\r
-       }\r
-\r
-}\r
+package org.simantics.excel.poi.parser;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+
+public abstract class CellDataResolverBase<T> implements DataResolver<T> {
+       
+               
+       protected Double getCellNumericValue(Cell cell) {
+               if (cell == null)
+                       return null;
+               switch (cell.getCellTypeEnum()) {
+               case BLANK:
+                       return null;
+               case BOOLEAN:
+                       return null;
+               case ERROR:
+                       return null;
+               case FORMULA:
+                       return null;
+               case NUMERIC:
+                       return cell.getNumericCellValue();
+               case STRING:
+                       return null;
+               case _NONE:
+                       return null;
+               }
+               throw new RuntimeException();
+       }
+       
+       protected String getCellStringValue(Cell cell) {
+               if (cell == null)
+                       return null;
+               switch (cell.getCellTypeEnum()) {
+               case BLANK:
+                       return null;
+               case BOOLEAN:
+                       return Boolean.toString(cell.getBooleanCellValue());
+               case ERROR:
+                       return null;
+               case FORMULA:
+                       return null;
+               case NUMERIC:
+                       return Double.toString(cell.getNumericCellValue());
+               case STRING:
+                       return cell.getStringCellValue();
+               case _NONE:
+                       return null;
+               }
+               throw new RuntimeException();
+       }
+       
+       protected Boolean getCellBooleanValue(Cell cell) {
+               if (cell == null)
+                       return null;
+               switch (cell.getCellTypeEnum()) {
+               case BLANK:
+                       return null;
+               case BOOLEAN:
+                       return cell.getBooleanCellValue();
+               case ERROR:
+                       return null;
+               case FORMULA:
+                       return null;
+               case NUMERIC:
+                       return null;
+               case STRING:
+                       String value = cell.getStringCellValue();
+                       if ("true".equalsIgnoreCase(value))
+                               return true;
+                       if ("1".equalsIgnoreCase(value))
+                               return true;
+                       return false;
+               case _NONE:
+                       return null;
+               
+               }
+               throw new RuntimeException();
+       }
+       
+       protected Cell getCell(Row row, int colIndex) {
+               short first = row.getFirstCellNum();
+               short last = row.getLastCellNum();
+               if (first < 0)
+                       return null;
+               for (short i = first; i <= last; i++) {
+                       Cell c = row.getCell(i);
+                       if (c == null)
+                               continue;
+                       if (c.getColumnIndex() == colIndex)
+                               return c;
+                       
+               }
+               return null;
+       }
+
+}