CsvStatisticsWriter implements StatisticsOutputter { @Override public void addToOutput(String bandName, String regionId, Map<String, Number> statistics) { if (!statisticsContainer.containsBand(bandName)) { statisticsContainer.put(bandName, new BandStatistics()); } final BandStatistics dataForBandName = statisticsContainer.getDataForBandName(bandName); if (!dataForBandName.containsRegion(regionId)) { dataForBandName.put(regionId, new RegionStatistics()); } final RegionStatistics dataForRegionName = dataForBandName.getDataForRegionName(regionId); for (Map.Entry<String, Number> entry : statistics.entrySet()) { dataForRegionName.put(entry.getKey(), entry.getValue()); } } CsvStatisticsWriter(PrintStream csvOutput); @Override void initialiseOutput(StatisticsOutputContext statisticsOutputContext); @Override void addToOutput(String bandName, String regionId, Map<String, Number> statistics); @Override void finaliseOutput();  }
@Test public void testAddToOutput() throws Exception { addOutput(); assertEquals(csvStatisticsWriter.statisticsContainer.getDataForBandName("normalised_cow_density_index_(ncdi)") .getDataForRegionName("werdohl") .getDataForAlgorithmName("p95").doubleValue(), 3.0, 1E-6); assertEquals(csvStatisticsWriter.statisticsContainer.getDataForBandName("normalised_cow_density_index_(ncdi)") .getDataForRegionName("werdohl") .getDataForAlgorithmName("p90").doubleValue(), 2.0, 1E-6); assertEquals(csvStatisticsWriter.statisticsContainer.getDataForBandName("normalised_pig_density_index_(npdi)") .getDataForRegionName("bielefeld") .getDataForAlgorithmName("p90").doubleValue(), 1.0, 1E-6); assertEquals(csvStatisticsWriter.statisticsContainer.getDataForBandName("normalised_pig_density_index_(npdi)") .getDataForRegionName("bielefeld") .getDataForAlgorithmName("p95").doubleValue(), 2.0, 1E-6); assertEquals(csvStatisticsWriter.statisticsContainer.getDataForBandName("normalised_pig_density_index_(npdi)") .getDataForRegionName("bielefeld") .getDataForAlgorithmName("max").doubleValue(), 3.0, 1E-6); assertEquals(csvStatisticsWriter.statisticsContainer.getDataForBandName("normalised_pig_density_index_(npdi)") .getDataForRegionName("bielefeld") .getDataForAlgorithmName("min").doubleValue(), 0.5, 1E-6); assertEquals(csvStatisticsWriter.statisticsContainer.getDataForBandName("normalised_cow_density_index_(ncdi)") .getDataForRegionName("bielefeld") .getDataForAlgorithmName("p90").doubleValue(), 1.0, 1E-6); }