public static ValidationResult validateTransfers(final TransitSchedule schedule) { ValidationResult result = new ValidationResult(); MinimalTransferTimes transferTimes = schedule.getMinimalTransferTimes(); MinimalTransferTimes.MinimalTransferTimesIterator iter = transferTimes.iterator(); Set<Id> missingFromStops = new HashSet<>(); Set<Id> missingToStops = new HashSet<>(); while (iter.hasNext()) { iter.next(); Id<TransitStopFacility> fromStopId = iter.getFromStopId(); Id<TransitStopFacility> toStopId = iter.getToStopId(); double transferTime = iter.getSeconds(); if (fromStopId == null && toStopId == null) { result.addError("Minimal Transfer Times: both fromStop and toStop are null."); } else if (fromStopId == null) { result.addError("Minimal Transfer Times: fromStop = null, toStop " + toStopId + "."); } else if (toStopId == null) { result.addError("Minimal Transfer Times: fromStop " + fromStopId + ", toStop = null."); } if (transferTime <= 0) { result.addWarning("Minimal Transfer Times: fromStop " + fromStopId + " toStop " + toStopId + " with transferTime = " + transferTime); } if (schedule.getFacilities().get(fromStopId) == null && missingFromStops.add(fromStopId)) { result.addError("Minimal Transfer Times: fromStop " + fromStopId + " does not exist in schedule."); } if (schedule.getFacilities().get(toStopId) == null && missingToStops.add(toStopId)) { result.addError("Minimal Transfer Times: toStop " + toStopId + " does not exist in schedule."); } } return result; }
Assert.assertFalse(iter.hasNext()); Assert.assertTrue(iter.hasNext()); try { iter.getFromStopId(); Assert.fail("expected Exception, got none."); } catch (NoSuchElementException expected) {} iter.next(); Assert.assertEquals(this.stopId1, iter.getFromStopId()); Assert.assertEquals(this.stopId2, iter.getToStopId()); Assert.assertEquals(120, iter.getSeconds(), 0.0); Assert.assertFalse(iter.hasNext()); iter.next(); Assert.fail("expected Exception, got none."); } catch (NoSuchElementException expected) {} iter.getFromStopId(); Assert.fail("expected Exception, got none."); } catch (NoSuchElementException expected) {} boolean found1to3 = false; boolean found2to3 = false; while (iter.hasNext()) { count++; iter.next(); Id<TransitStopFacility> fromStopId = iter.getFromStopId();
@Test public void testIterator_empty() { MinimalTransferTimes mtt = new MinimalTransferTimesImpl(); MinimalTransferTimes.MinimalTransferTimesIterator iter = mtt.iterator(); Assert.assertFalse(iter.hasNext()); try { iter.getFromStopId(); Assert.fail("expected Exception, got none."); } catch (NoSuchElementException expected) {} try { iter.getToStopId(); Assert.fail("expected Exception, got none."); } catch (NoSuchElementException expected) {} try { iter.getSeconds(); Assert.fail("expected Exception, got none."); } catch (NoSuchElementException expected) {} try { iter.next(); Assert.fail("expected Exception"); } catch (NoSuchElementException expected) {} try { iter.getFromStopId(); // there should still be an exception after calling next() Assert.fail("expected Exception, got none."); } catch (NoSuchElementException expected) {} }
private void writeMinimalTransferTimes() { List<Tuple<String, String>> attributes = new ArrayList<>(5); MinimalTransferTimes.MinimalTransferTimesIterator iter = this.schedule.getMinimalTransferTimes().iterator(); if (iter.hasNext()) { this.writeStartTag(Constants.MINIMAL_TRANSFER_TIMES, attributes); while (iter.hasNext()) { iter.next(); attributes.clear(); attributes.add(createTuple(Constants.FROM_STOP, iter.getFromStopId().toString())); attributes.add(createTuple(Constants.TO_STOP, iter.getToStopId().toString())); attributes.add(createTuple(Constants.TRANSFER_TIME, iter.getSeconds())); this.writeStartTag(Constants.RELATION, attributes, true); } this.writeEndTag(Constants.MINIMAL_TRANSFER_TIMES); } }