List of usage examples for org.joda.time LocalTime parse
@FromString public static LocalTime parse(String str)
From source file:br.com.tecsinapse.datasources.DataParser.java
License:LGPL
public DataParser(String date, String dateTime, String decimal, Integer integer, String string, String empty, String time) {// www. jav a 2 s.c o m this.date = LocalDate.parse(date); this.dateTime = LocalDateTime.parse(dateTime); this.decimal = decimal != null ? new BigDecimal(decimal) : null; this.integer = integer; this.string = string; this.empty = empty; this.time = LocalTime.parse(time); }
From source file:br.com.tecsinapse.exporter.converter.LocalTimeTableCellConverter.java
License:LGPL
@Override public LocalTime apply(String input) { return Strings.isNullOrEmpty(input) ? null : LocalTime.parse(input); }
From source file:ch.aonyx.broker.ib.api.account.AccountUpdateTimeEvent.java
License:Apache License
public DateTime getDateTime() { return LocalTime.parse(time).toDateTimeToday(); }
From source file:ch.oakmountain.tpa.parser.TpaParser.java
License:Apache License
/** * Put the train path ids in the format <train_path_slot_id><hour_of_day_>-<three_digit_sequence_number_within_hour> * * @param wsName/*from w ww . j a v a 2s .c o m*/ * @param rowsFrom * @param cols */ private void correctTrainPathIds(String wsName, int rowsFrom, Map<ColumnIdentifier, Integer> cols) { Sheet sheet = wb.getSheet(wsName); for (int i = rowsFrom; i <= sheet.getLastRowNum(); i++) { Row row = sheet.getRow(i); if (row == null) { continue; } Map<ColumnIdentifier, String> line = getWorksheetPointerStringMap(cols, row); String uncorrectedSlotName = line.get(trainPathLayout.ID); if (StringUtils.isBlank(uncorrectedSlotName)) { continue; } try { LocalTime startTime = LocalTime.parse(line.get(trainPathLayout.DEPTIME)); String correctedSlotName = getNextSlotId(wsName, startTime.getHourOfDay()); if (!correctedSlotName.equals(uncorrectedSlotName)) { LOGGER.warn("Correcting slot name " + uncorrectedSlotName + " => " + correctedSlotName); row.getCell(cols.get(trainPathLayout.ID)).setCellValue(correctedSlotName); } } catch (IllegalArgumentException e) { LOGGER.warn(corrupt_input, "Illegal start time \"" + line.get(trainPathLayout.DEPTIME) + "\" for slot " + uncorrectedSlotName + " in sheet " + wsName + " found; skipping this slot.", e); continue; } } }
From source file:ch.oakmountain.tpa.parser.TpaParser.java
License:Apache License
public TrainPathSlotCatalogue readTrainPathCatalogue(MacroscopicTopology macroscopicTopology, boolean clean, boolean correctTrainPathIds) { List<String> linkNames = macroscopicTopology.getLinkNames(); TrainPathSlotCatalogue catalogue = new TrainPathSlotCatalogue(); String colLayoutString = getPropertyValue(tpaProps.TRAINPATHS_COL_LAYOUT); List<ColumnIdentifier> cols = new ArrayList<ColumnIdentifier>(trainPathLayout.values().length); for (trainPathLayout l : trainPathLayout.values()) { cols.add(l);/*from w w w. ja v a 2 s . com*/ } Map<ColumnIdentifier, Integer> colLayoutMapping = getColLayoutMapping(colLayoutString, cols); for (String linkName : linkNames) { int headerRowsNb = Integer.parseInt(getPropertyValue(tpaProps.TRAINPATHS_WS_HEADER_ROWS)); if (clean) { List<Integer> colsToDelete = new LinkedList<>(); colsToDelete.add(colLayoutMapping.get(trainPathLayout.MON)); colsToDelete.add(colLayoutMapping.get(trainPathLayout.TUE)); colsToDelete.add(colLayoutMapping.get(trainPathLayout.WED)); colsToDelete.add(colLayoutMapping.get(trainPathLayout.THU)); colsToDelete.add(colLayoutMapping.get(trainPathLayout.FRI)); colsToDelete.add(colLayoutMapping.get(trainPathLayout.SAT)); colsToDelete.add(colLayoutMapping.get(trainPathLayout.SUN)); emptyWorksheetColumns(linkName, headerRowsNb, colsToDelete); } if (correctTrainPathIds) { correctTrainPathIds(linkName, headerRowsNb, colLayoutMapping); } List<Map<ColumnIdentifier, String>> lines = readWorksheet(linkName, headerRowsNb, colLayoutMapping); Pair<SystemNode, SystemNode> link = macroscopicTopology.getLink(linkName); for (Map<ColumnIdentifier, String> line : lines) { if (StringUtils.isBlank(line.get(trainPathLayout.ID))) { continue; } else if (StringUtils.isBlank(line.get(trainPathLayout.DEPTIME))) { LOGGER.warn(corrupt_input, "Train path slot " + line.get(trainPathLayout.ID) + " has empty start time!"); continue; } else if (StringUtils.isBlank(line.get(trainPathLayout.ARRTIME))) { LOGGER.warn(corrupt_input, "Train path slot " + line.get(trainPathLayout.ID) + " has empty end time!"); continue; } String slotName = line.get(trainPathLayout.ID); LocalTime startTime = LocalTime.parse(line.get(trainPathLayout.DEPTIME)); LocalTime endTime = LocalTime.parse(line.get(trainPathLayout.ARRTIME)); try { SystemNode from = link.first; SystemNode to = link.second; Periodicity periodicity = new Periodicity(); for (trainPathLayout weekDay : trainPathLayout.weekDays) { periodicity.setWeekDay(trainPathLayout.getWeekDay(weekDay), StringUtils.isBlank(line.get(weekDay))); } catalogue.add(linkName, slotName, startTime, endTime, from, to, periodicity); } catch (IllegalArgumentException e) { LOGGER.warn(corrupt_input, "Skipping slot " + slotName, e); continue; } } } return catalogue; }
From source file:ch.oakmountain.tpa.parser.TpaParser.java
License:Apache License
/** * Read the requests from the input file and filter them. * * @param macroscopicTopology/*from w w w .j av a2s . co m*/ * @param requestFilterLower * @param requestFilterUpper * @param clean * @param ignoreCompletelyAllocatedRequests * @return */ public List<TrainPathApplication> readRequests(MacroscopicTopology macroscopicTopology, Periodicity requestFilterLower, Periodicity requestFilterUpper, boolean clean, boolean ignoreCompletelyAllocatedRequests, int hardMaximumEarlierDeparture, int hardMinimumDwellTime, int hardMaximumLaterArrival) { List<TrainPathApplication> requests = new LinkedList<TrainPathApplication>(); String colLayoutString = getPropertyValue(tpaProps.REQUESTS_COL_LAYOUT); List<ColumnIdentifier> cols = new ArrayList<ColumnIdentifier>(requestsLayout.values().length); for (requestsLayout l : requestsLayout.values()) { cols.add(l); } Map<ColumnIdentifier, Integer> colLayoutMapping = getColLayoutMapping(colLayoutString, cols); if (clean) { List<Integer> colsToDelete = new LinkedList<>(); colsToDelete.add(colLayoutMapping.get(requestsLayout.MON)); colsToDelete.add(colLayoutMapping.get(requestsLayout.TUE)); colsToDelete.add(colLayoutMapping.get(requestsLayout.WED)); colsToDelete.add(colLayoutMapping.get(requestsLayout.THU)); colsToDelete.add(colLayoutMapping.get(requestsLayout.FRI)); colsToDelete.add(colLayoutMapping.get(requestsLayout.SAT)); colsToDelete.add(colLayoutMapping.get(requestsLayout.SUN)); resetRequestAllocations(getPropertyValue(tpaProps.REQUESTS_WS_NAME), Integer.parseInt(getPropertyValue(tpaProps.REQUESTS_WS_HEADER_ROWS)), colsToDelete); } String wsName = getPropertyValue(tpaProps.REQUESTS_WS_NAME); int headerRowsNb = Integer.parseInt(getPropertyValue(tpaProps.REQUESTS_WS_HEADER_ROWS)); List<Map<ColumnIdentifier, String>> lines = readWorksheet(wsName, headerRowsNb, colLayoutMapping); // Map is used to generate requests from current allocations Map<String, Map<ColumnIdentifier, String>> map = new HashMap<String, Map<ColumnIdentifier, String>>(); for (Map<ColumnIdentifier, String> line : lines) { String requestNr = line.get(requestsLayout.ID); if (StringUtils.isBlank(requestNr)) { continue; } if (StringUtils.isBlank(line.get(requestsLayout.FROM))) { LOGGER.warn(TpaParser.corrupt_input, "Request " + requestNr + " has empty start node!"); continue; } if (StringUtils.isBlank(line.get(requestsLayout.TO))) { LOGGER.warn(TpaParser.corrupt_input, "Request " + requestNr + " has empty end node!"); continue; } if (StringUtils.isBlank(line.get(requestsLayout.DEPTIME))) { LOGGER.warn(TpaParser.corrupt_input, "Request " + requestNr + " has empty departure time!"); continue; } if (StringUtils.isBlank(line.get(requestsLayout.ARRTIME))) { LOGGER.warn(TpaParser.corrupt_input, "Request " + requestNr + " has empty arrival time!"); continue; } String name = line.get(requestsLayout.ID); try { SystemNode from = macroscopicTopology .getSystemNode(getUniqueSystemNode(line.get(requestsLayout.FROM))); SystemNode to = macroscopicTopology.getSystemNode(getUniqueSystemNode(line.get(requestsLayout.TO))); if (from.equals(to)) { throw new IllegalArgumentException( "From (" + from + ") and to node (" + to + ") must not be the same."); } LocalTime startTime = LocalTime.parse(line.get(requestsLayout.DEPTIME)); LocalTime endTime = LocalTime.parse(line.get(requestsLayout.ARRTIME)); Periodicity periodicity = new Periodicity(); for (requestsLayout weekDay : requestsLayout.weekDays) { periodicity.setWeekDay(requestsLayout.getWeekDay(weekDay), getPropertyValue(tpaProps.REQUESTS_REQUESTED_DAY_MARKER).equals(line.get(weekDay))); } // Add request if contained in filter bounds if (ignoreCompletelyAllocatedRequests && periodicity.getWeekDays().size() == 0) { LOGGER.debug("Filtered out request " + name + " since " + periodicity.getStringRepresentation() + " no unallocated day."); continue; } if (periodicity.containedWithin(requestFilterLower, requestFilterUpper)) { TrainPathApplication r = new TrainPathApplication(name, from, to, startTime, endTime, periodicity, hardMaximumEarlierDeparture, hardMinimumDwellTime, hardMaximumLaterArrival); requests.add(r); LOGGER.debug( "Filtered in request " + r.getName() + " since " + periodicity.getStringRepresentation() + " in [" + requestFilterLower.getStringRepresentation() + "," + requestFilterUpper.getStringRepresentation() + "]"); } else { LOGGER.debug("Filtered out request " + name + " since " + periodicity.getStringRepresentation() + " not in [" + requestFilterLower.getStringRepresentation() + "," + requestFilterUpper.getStringRepresentation() + "]"); } } catch (IllegalArgumentException e) { LOGGER.warn(TpaParser.corrupt_input, "Skipping request " + name, e); continue; } } return requests; }
From source file:ch.oakmountain.tpa.solver.TrainPathSlotCatalogue.java
License:Apache License
public static TrainPathSlotCatalogue generateTestTrainPathCatalogue(MacroscopicTopology macroscopicTopology, int trainsPerHour, int durationMinutes) { TrainPathSlotCatalogue catalogue = new TrainPathSlotCatalogue(); List<String> linkNames = macroscopicTopology.getLinkNames(); for (String linkName : linkNames) { Pair<SystemNode, SystemNode> link = macroscopicTopology.getLink(linkName); SystemNode fromNode = link.first; SystemNode toNode = link.second; // train path slots hourly for (int i = 0; i < 24; i++) { for (int j = 0; j < trainsPerHour; j++) { int hour = i; int minutes = j * (60 / trainsPerHour); String deptimestring = String.format("%02d", hour) + ":" + String.format("%02d", minutes); int arrtime = hour * 60 + minutes + durationMinutes; String arrtimestring = String.format("%02d", ((arrtime / 60)) % 24) + ":" + String.format("%02d", arrtime % 60); String slotName = linkName + "_" + String.format("%03d", hour) + "_" + String.format("%03d", j); catalogue.add(linkName, slotName, LocalTime.parse(deptimestring), LocalTime.parse(arrtimestring), fromNode, toNode, Periodicity.getWholeWeekPeriodicity()); }//from w w w .j a v a 2 s .co m } } return catalogue; }
From source file:com.alliander.osgp.adapter.protocol.oslp.elster.infra.networking.OslpDeviceService.java
License:Open Source License
private List<Oslp.Schedule> convertToOslpSchedules(final List<ScheduleDto> schedules) { final List<Oslp.Schedule> oslpSchedules = new ArrayList<Oslp.Schedule>(); for (final ScheduleDto schedule : schedules) { Oslp.Schedule.Builder scheduleBuilder = Oslp.Schedule.newBuilder() .setWeekday(Oslp.Weekday.valueOf(schedule.getWeekDay().ordinal() + 1)) .setActionTime(Oslp.ActionTime.valueOf(schedule.getActionTime().ordinal() + 1)); if (schedule.getStartDay() != null) { scheduleBuilder = scheduleBuilder.setStartDay(schedule.getStartDay().toString(DATE_FORMAT)); }// w w w .j a v a2 s . co m if (schedule.getEndDay() != null) { scheduleBuilder = scheduleBuilder.setEndDay(schedule.getEndDay().toString(DATE_FORMAT)); } if (StringUtils.isNotBlank(schedule.getTime())) { scheduleBuilder = scheduleBuilder .setTime(LocalTime.parse(schedule.getTime()).toString(TIME_FORMAT)); } if (schedule.getTriggerWindow() != null) { scheduleBuilder = scheduleBuilder.setWindow(Oslp.Window.newBuilder() .setMinutesBefore((int) schedule.getTriggerWindow().getMinutesBefore()) .setMinutesAfter((int) schedule.getTriggerWindow().getMinutesAfter())); } for (final LightValueDto lightValue : schedule.getLightValue()) { scheduleBuilder.addValue(this.buildLightValue(lightValue)); } if (schedule.getTriggerType() != null) { scheduleBuilder.setTriggerType(Oslp.TriggerType.valueOf(schedule.getTriggerType().ordinal() + 1)); } if (schedule.getIndex() != null) { scheduleBuilder.setIndex(schedule.getIndex()); } if (schedule.getIsEnabled() != null) { scheduleBuilder.setIsEnabled(schedule.getIsEnabled()); } if (schedule.getMinimumLightsOn() != null) { scheduleBuilder.setMinimumLightsOn(schedule.getMinimumLightsOn()); } oslpSchedules.add(scheduleBuilder.build()); } return oslpSchedules; }
From source file:com.alliander.osgp.adapter.protocol.oslp.infra.networking.OslpDeviceService.java
License:Open Source License
private List<Oslp.Schedule> convertToOslpSchedules(final List<ScheduleDto> schedules) { final List<Oslp.Schedule> oslpSchedules = new ArrayList<Oslp.Schedule>(); for (final ScheduleDto schedule : schedules) { Oslp.Schedule.Builder scheduleBuilder = Oslp.Schedule.newBuilder() .setWeekday(Oslp.Weekday.valueOf(schedule.getWeekDay().ordinal() + 1)) .setActionTime(Oslp.ActionTime.valueOf(schedule.getActionTime().ordinal() + 1)); if (schedule.getStartDay() != null) { scheduleBuilder = scheduleBuilder.setStartDay(schedule.getStartDay().toString(DATE_FORMAT)); }//from w w w . j a v a2 s. c o m if (schedule.getEndDay() != null) { scheduleBuilder = scheduleBuilder.setEndDay(schedule.getEndDay().toString(DATE_FORMAT)); } if (StringUtils.isNotBlank(schedule.getTime())) { scheduleBuilder = scheduleBuilder .setTime(LocalTime.parse(schedule.getTime()).toString(TIME_FORMAT)); } if (schedule.getTriggerWindow() != null) { scheduleBuilder = scheduleBuilder.setWindow(Oslp.Window.newBuilder() .setMinutesBefore((int) schedule.getTriggerWindow().getMinutesBefore()) .setMinutesAfter((int) schedule.getTriggerWindow().getMinutesAfter())); } for (final LightValueDto lightValue : schedule.getLightValue()) { scheduleBuilder.addValue(this.buildLightValue(lightValue)); } if (schedule.getTriggerType() != null) { scheduleBuilder.setTriggerType(Oslp.TriggerType.valueOf(schedule.getTriggerType().ordinal() + 1)); } oslpSchedules.add(scheduleBuilder.build()); } return oslpSchedules; }
From source file:com.datastax.driver.extras.codecs.joda.LocalTimeCodec.java
License:Apache License
@Override public LocalTime parse(String value) { if (value == null || value.isEmpty() || value.equalsIgnoreCase("NULL")) return null; // enclosing single quotes required, even for long literals if (!ParseUtils.isQuoted(value)) throw new InvalidTypeException("time values must be enclosed by single quotes"); value = value.substring(1, value.length() - 1); if (ParseUtils.isLongLiteral(value)) { long nanosOfDay; try {//from w ww . j ava2 s . c om nanosOfDay = Long.parseLong(value); } catch (NumberFormatException e) { throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); } return LocalTime.fromMillisOfDay(NANOSECONDS.toMillis(nanosOfDay)); } try { return LocalTime.parse(value); } catch (RuntimeException e) { throw new InvalidTypeException(String.format("Cannot parse time value from \"%s\"", value), e); } }