Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected Double validateDoubleNotNegative(Row row, int idx, int format, boolean mandatory) {
- Cell cell = row.getCell(idx);
- boolean isValueNegativeOne = false;
- boolean isNaN = false;
- if (cell == null || cell.getCellType() == Cell.CELL_TYPE_BLANK ||
- (cell.getCellType() == Cell.CELL_TYPE_STRING && cell.getStringCellValue().isEmpty())) {
- return null;
- } else {
- //make sure its a number
- try {
- //makes sure the value from the user isn't -1 as opposed to the -1 returned by parseDouble below
- double num = cell.getNumericCellValue();
- if (num == -1.0) {
- isValueNegativeOne = true;
- }
- isNaN = false;
- } catch (IllegalStateException e) {
- //could be an empty formula
- if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
- String str = cell.getStringCellValue();
- if ( ! str.isEmpty()) {
- //it's not an empty formula cell
- isNaN = true;
- }
- } else {
- isNaN = true;
- }
- }
- }
- Double result = Utility.parseDouble(getCellValue(row, idx, format, mandatory) + "", -1);
- if(result == null || (result.equals(-1.0) && ! isValueNegativeOne && ! isNaN)) {
- return null;
- } else if (result != null && isNaN) {
- DataUploadCheckList mandatoryArgumentCheck = new DataUploadCheckList();
- mandatoryArgumentCheck.setSheetName(row.getSheet().getSheetName());
- mandatoryArgumentCheck.setCheckListFlag(DataUploadConstants.ERROR);
- mandatoryArgumentCheck.setDescription(
- DataUploadConstants.INVALID_VALUE_ERROR
- + cell.getRow().getSheet().getRow(0).getCell(cell.getColumnIndex()).getStringCellValue().replaceAll("\n", "").trim()
- + DataUploadConstants.NAN_VALUE_ERROR);
- mandatoryArgumentCheck.setRowNumber((long) row.getRowNum());
- this.mandatoryAttributesErrorList.add(mandatoryArgumentCheck);
- result = null;
- } else if (result != null && result.doubleValue() < 0.0) {
- DataUploadCheckList mandatoryArgumentCheck = new DataUploadCheckList();
- mandatoryArgumentCheck.setSheetName(row.getSheet().getSheetName());
- mandatoryArgumentCheck.setCheckListFlag(DataUploadConstants.ERROR);
- mandatoryArgumentCheck.setDescription(
- DataUploadConstants.INVALID_VALUE_ERROR
- + cell.getRow().getSheet().getRow(0).getCell(cell.getColumnIndex()).getStringCellValue().replaceAll("\n", "").trim()
- + DataUploadConstants.NEGATIVE_VALUE_ERROR);
- mandatoryArgumentCheck.setRowNumber((long) row.getRowNum());
- this.mandatoryAttributesErrorList.add(mandatoryArgumentCheck);
- result = null;
- }
- return result;
- }
Add Comment
Please, Sign In to add comment