private void writeTransitLine(final TransitLine line) throws UncheckedIOException { List<Tuple<String, String>> attributes = new ArrayList<Tuple<String, String>>(1); attributes.add(this.createTuple(Constants.ID, line.getId().toString())); if (line.getName() != null) { attributes.add(this.createTuple(Constants.NAME, line.getName())); } this.writeStartTag(Constants.TRANSIT_LINE, attributes); for (TransitRoute route : line.getRoutes().values()) { writeTransitRoute(route); } this.writeEndTag(Constants.TRANSIT_LINE); }
private void writeTransitLine(final TransitLine line) throws IOException, UncheckedIOException { List<Tuple<String, String>> attributes = new ArrayList<>(1); attributes.add(createTuple(Constants.ID, line.getId().toString())); if (line.getName() != null) { attributes.add(createTuple(Constants.NAME, line.getName())); } this.writeStartTag(Constants.TRANSIT_LINE, attributes); if (!AttributesUtils.isEmpty(line.getAttributes())) { this.writer.write(NL); this.attributesWriter.writeAttributes("\t\t", this.writer, line.getAttributes()); } for (TransitRoute route : line.getRoutes().values()) { writeTransitRoute(route); } this.writeEndTag(Constants.TRANSIT_LINE); }
@Test public void testTransitLineName() { String filename = this.utils.getOutputDirectory() + "schedule.xml"; TransitScheduleFactory builder = new TransitScheduleFactoryImpl(); TransitSchedule schedule = builder.createTransitSchedule(); TransitLine line = builder.createTransitLine(Id.create(1, TransitLine.class)); line.setName("Blue line"); schedule.addTransitLine(line); TransitScheduleWriter writer = new TransitScheduleWriter(schedule); writer.writeFile(filename); TransitScheduleFactory builder2 = new TransitScheduleFactoryImpl(); TransitSchedule schedule2 = builder2.createTransitSchedule(); new TransitScheduleReaderV1(schedule2, new RouteFactories()).readFile(filename); Assert.assertEquals(1, schedule2.getTransitLines().size()); Assert.assertEquals("Blue line", schedule2.getTransitLines().get(Id.create(1, TransitLine.class)).getName()); } }