@Override public Counts<Link> get() { Counts<Link> calibrationCounts = new Counts<>(); new MatsimCountsReader(calibrationCounts).parse(config.getCountsFileURL(matsimConfig.getContext())); return calibrationCounts; } }
@Test public void testDefaultYear_empty() { Counts counts = new Counts(); ByteArrayOutputStream out = new ByteArrayOutputStream(); new CountsWriter(counts).write(out); Counts counts2 = new Counts(); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); new MatsimCountsReader(counts2).parse(in); // there should not have been an Exception }
@Provides @Singleton Counts<Link> provideLinkCounts(Scenario scenario, CountsConfigGroup config) { Counts<Link> counts = (Counts<Link>) scenario.getScenarioElement(Counts.ELEMENT_NAME); if (counts != null) { return counts; } else { counts = new Counts<>(); if (config.getCountsFileName() != null) { final String inputCRS = config.getInputCRS(); final String internalCRS = scenario.getConfig().global().getCoordinateSystem(); MatsimCountsReader counts_parser; if (inputCRS == null) { counts_parser = new MatsimCountsReader(counts); } else { log.info( "re-projecting counts from "+inputCRS+" to "+internalCRS+" for import" ); final CoordinateTransformation transformation = TransformationFactory.getCoordinateTransformation( inputCRS, internalCRS ); counts_parser = new MatsimCountsReader( transformation , counts ); } counts_parser.parse(config.getCountsFileURL(scenario.getConfig().getContext())); } return counts; } }
MatsimCountsReader reader = new MatsimCountsReader(counts); ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); reader.parse(stream); Assert.assertEquals(1, counts.getCounts().size());
MatsimCountsReader reader = new MatsimCountsReader(counts); ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); reader.parse(stream); Assert.assertEquals(1, counts.getCounts().size());