@Override public double getNumericCellValue() { return _cell.getNumericCellValue(); } @Override
private int getNextStrictlyPositiveIntegerCell(String classSpecifier, String columnName) { double cellValueDouble = nextNumericCell().getNumericCellValue(); if (strict && (cellValueDouble <= 0 || cellValueDouble != Math.floor(cellValueDouble))) { throw new IllegalStateException(currentPosition() + ": The" + classSpecifier + ")'s has " + columnName + " (" + cellValueDouble + ") that isn't a strictly positive integer number."); } return (int) cellValueDouble; }
private int getNextPositiveIntegerCell(String classSpecifier, String columnName) { double cellValueDouble = nextNumericCell().getNumericCellValue(); if (strict && (cellValueDouble < 0 || cellValueDouble != Math.floor(cellValueDouble))) { throw new IllegalStateException(currentPosition() + ": The " + classSpecifier + ")'s has " + columnName + " (" + cellValueDouble + ") that isn't a positive integer number."); } return (int) cellValueDouble; }
protected void readHeaderCell(double value) { XSSFCell cell = currentRow == null ? null : nextNumericCell(); if (cell == null || cell.getNumericCellValue() != value) { throw new IllegalStateException(currentPosition() + ": The cell does not contain the expected value (" + value + ")."); } }
protected XSSFCell nextStringCell() { XSSFCell cell = nextCell(); if (cell.getCellTypeEnum() == CellType.NUMERIC) { throw new IllegalStateException(currentPosition() + ": The cell with value (" + cell.getNumericCellValue() + ") has a numeric type but should be a string."); } return cell; }
private void readMeetingDuration(Meeting meeting) { double durationDouble = nextNumericCell().getNumericCellValue(); if (durationDouble <= 0 || durationDouble != Math.floor(durationDouble)) { throw new IllegalStateException( currentPosition() + ": The meeting with id (" + meeting.getId() + ")'s has a duration (" + durationDouble + ") that isn't a strictly positive integer number."); } if (durationDouble % TimeGrain.GRAIN_LENGTH_IN_MINUTES != 0) { throw new IllegalStateException( currentPosition() + ": The meeting with id (" + meeting.getId() + ") has a duration (" + durationDouble + ") that isn't a multiple of " + TimeGrain.GRAIN_LENGTH_IN_MINUTES + "."); } meeting.setDurationInGrains((int) durationDouble / TimeGrain.GRAIN_LENGTH_IN_MINUTES); }
protected XSSFCell nextBooleanCell() { XSSFCell cell = nextCell(); if (cell.getCellTypeEnum() == CellType.STRING) { throw new IllegalStateException(currentPosition() + ": The cell with value (" + cell.getStringCellValue() + ") has a string type but should be boolean."); } if (cell.getCellTypeEnum() == CellType.NUMERIC) { throw new IllegalStateException(currentPosition() + ": The cell with value (" + cell.getNumericCellValue() + ") has a numeric type but should be a boolean."); } return cell; }
double drivingTimeDouble = nextNumericCell().getNumericCellValue(); long drivingTime = (long) drivingTimeDouble; if (drivingTimeDouble != (double) drivingTime) {
Date date = sdf.parse(value); cell.setCellValue(date); if (!DateUtil.isValidExcelDate(cell.getNumericCellValue())) { cell.setCellValue(value);
protected void readIntConstraintParameterLine(String name, Consumer<Integer> consumer, String constraintDescription) { nextRow(); readHeaderCell(name); XSSFCell weightCell = nextCell(); if (consumer != null) { if (weightCell.getCellTypeEnum() != CellType.NUMERIC) { throw new IllegalArgumentException(currentPosition() + ": The value (" + weightCell.getStringCellValue() + ") for constraint (" + name + ") must be a number and the cell type must be numeric."); } double value = weightCell.getNumericCellValue(); if (((double) ((int) value)) != value) { throw new IllegalArgumentException(currentPosition() + ": The value (" + value + ") for constraint (" + name + ") must be an integer."); } consumer.accept((int) value); } else { if (weightCell.getCellTypeEnum() == CellType.NUMERIC || !weightCell.getStringCellValue().equals("n/a")) { throw new IllegalArgumentException(currentPosition() + ": The value (" + weightCell.getStringCellValue() + ") for constraint (" + name + ") must be an n/a."); } } readHeaderCell(constraintDescription); }
protected void readLongConstraintParameterLine(String name, Consumer<Long> consumer, String constraintDescription) { nextRow(); readHeaderCell(name); XSSFCell weightCell = nextCell(); if (consumer != null) { if (weightCell.getCellTypeEnum() != CellType.NUMERIC) { throw new IllegalArgumentException(currentPosition() + ": The value (" + weightCell.getStringCellValue() + ") for constraint (" + name + ") must be a number and the cell type must be numeric."); } double value = weightCell.getNumericCellValue(); if (((double) ((long) value)) != value) { throw new IllegalArgumentException(currentPosition() + ": The value (" + value + ") for constraint (" + name + ") must be a (long) integer."); } consumer.accept((long) value); } else { if (weightCell.getCellTypeEnum() == CellType.NUMERIC || !weightCell.getStringCellValue().equals("n/a")) { throw new IllegalArgumentException(currentPosition() + ": The value (" + weightCell.getStringCellValue() + ") for constraint (" + name + ") must be an n/a."); } } readHeaderCell(constraintDescription); }
/** * Get the value of the cell as a date. * <p> * For strings we throw an exception. For blank cells we return a null. * </p> * @return the value of the cell as a date * @throws IllegalStateException if the cell type returned by {@link #getCellType()} is {@link CellType#STRING} * @exception NumberFormatException if the cell value isn't a parsable <code>double</code>. * @see DataFormatter for formatting this date into a string similar to how excel does. */ @Override public Date getDateCellValue() { if (getCellType() == CellType.BLANK) { return null; } double value = getNumericCellValue(); boolean date1904 = getSheet().getWorkbook().isDate1904(); return DateUtil.getJavaDate(value, date1904); }
private void readRoomList() { nextSheet("Rooms"); nextRow(); readHeaderCell("Name"); readHeaderCell("Capacity"); List<Room> roomList = new ArrayList<>(currentSheet.getLastRowNum() - 1); long id = 0L; while (nextRow()) { Room room = new Room(); room.setId(id++); room.setName(nextStringCell().getStringCellValue()); if (!VALID_NAME_PATTERN.matcher(room.getName()).matches()) { throw new IllegalStateException( currentPosition() + ": The room name (" + room.getName() + ") must match to the regular expression (" + VALID_NAME_PATTERN + ")."); } double capacityDouble = nextNumericCell().getNumericCellValue(); if (capacityDouble <= 0 || capacityDouble != Math.floor(capacityDouble)) { throw new IllegalStateException( currentPosition() + ": The room with name (" + room.getName() + ") has a capacity (" + capacityDouble + ") that isn't a strictly positive integer number."); } room.setCapacity((int) capacityDouble); roomList.add(room); } solution.setRoomList(roomList); } }
return sdf.format(getDateCellValue()); return Double.toString(getNumericCellValue()); case STRING: return getRichStringCellValue().toString();
private void readAirportList() { nextSheet("Airports"); nextRow(false); readHeaderCell("Code"); readHeaderCell("Name"); readHeaderCell("Latitude"); readHeaderCell("Longitude"); List<Airport> airportList = new ArrayList<>(currentSheet.getLastRowNum() - 1); airportMap = new HashMap<>(currentSheet.getLastRowNum() - 1); long id = 0L; while (nextRow()) { Airport airport = new Airport(); airport.setId(id++); airport.setCode(nextStringCell().getStringCellValue()); airport.setName(nextStringCell().getStringCellValue()); airport.setLatitude(nextNumericCell().getNumericCellValue()); airport.setLongitude(nextNumericCell().getNumericCellValue()); airportMap.put(airport.getCode(), airport); airportList.add(airport); } solution.setAirportList(airportList); }
private void readTaxiTimeMaps() { nextSheet("Taxi time"); nextRow(); readHeaderCell("Driving time in minutes by taxi between two nearby airports to allow employees to start from a different airport."); List<Airport> airportList = solution.getAirportList(); nextRow(); readHeaderCell("Airport code"); for (Airport airport : airportList) { readHeaderCell(airport.getCode()); } for (Airport a : airportList) { a.setTaxiTimeInMinutesMap(new LinkedHashMap<>(airportList.size())); nextRow(); readHeaderCell(a.getCode()); for (Airport b : airportList) { XSSFCell taxiTimeCell = nextNumericCellOrBlank(); if (taxiTimeCell != null) { a.getTaxiTimeInMinutesMap().put(b, (long) taxiTimeCell.getNumericCellValue()); } } } }
private void readBus() { nextSheet("Bus"); RockBus bus = new RockBus(); bus.setId(0L); nextRow(); readHeaderCell(""); readHeaderCell("City name"); readHeaderCell("Latitude"); readHeaderCell("Longitude"); readHeaderCell("Date"); nextRow(); readHeaderCell("Bus start"); String startCityName = nextStringCell().getStringCellValue(); double startLatitude = nextNumericCell().getNumericCellValue(); double startLongitude = nextNumericCell().getNumericCellValue(); bus.setStartLocation(new RockLocation(startCityName, startLatitude, startLongitude)); bus.setStartDate(LocalDate.parse(nextStringCell().getStringCellValue(), DAY_FORMATTER)); nextRow(); readHeaderCell("Bus end"); String endCityName = nextStringCell().getStringCellValue(); double endLatitude = nextNumericCell().getNumericCellValue(); double endLongitude = nextNumericCell().getNumericCellValue(); bus.setEndLocation(new RockLocation(endCityName, endLatitude, endLongitude)); bus.setEndDate(LocalDate.parse(nextStringCell().getStringCellValue(), DAY_FORMATTER)); solution.setBus(bus); }
value = getFormattedDate(cell); } else { value += cell.getNumericCellValue();
show.setVenueName(nextStringCell().getStringCellValue()); String cityName = nextStringCell().getStringCellValue(); double latitude = nextNumericCell().getNumericCellValue(); double longitude = nextNumericCell().getNumericCellValue(); show.setLocation(new RockLocation(cityName, latitude, longitude)); double duration = nextNumericCell().getNumericCellValue(); int durationInHalfDay = (int) (duration * 2.0); if (((double) durationInHalfDay) != duration * 2.0) { double revenueOpportunityDouble = nextNumericCell().getNumericCellValue(); if (revenueOpportunityDouble != (double) (int) revenueOpportunityDouble) { throw new IllegalStateException(currentPosition() + ": The show (" + show.getVenueName()
nextRow(false); readHeaderCell("Score weight multiplier"); double weightMultiplierDouble = nextNumericCell().getNumericCellValue(); if (weightMultiplierDouble != (double) (int) weightMultiplierDouble) { throw new IllegalStateException(currentPosition() + ": The weightMultiplier (" + weightMultiplierDouble