/** * @return A {@link StringList} of all the lines in this resource. */ default StringList linesList() { return new StringList(lines()); }
protected static Node read(final Resource resource) { return read(resource.lines().iterator()); }
/** * @return The contents of the resource as a String */ default String readAndClose() { final StringList builder = new StringList(); lines().forEach(builder::add); return builder.join(System.lineSeparator()); }
public CountryToShardListCache(final Resource resource) { try { resource.lines().forEach(line -> { final String[] countryAndShardList = line.split(Pattern.quote(DELIMITER)); final String country = countryAndShardList[0]; final String shardList = countryAndShardList[1]; Arrays.asList(shardList.split("\\s*,\\s*")).stream().map(SlippyTile::forName) .forEach(slippyTile -> this.countryToShards.add(country, slippyTile)); }); } catch (final Exception e) { throw new CoreException("Error while reading CountryToShardListCache resource", e); } }
/** * @return The full contents of the {@link Resource} as a {@link String} */ default String all() { return new StringList(lines()).join("\n"); }
@Override public Iterable<String> lines() { return Iterables.stream(this.source.lines()).filter(this.lineFilter).collect(); }
public void update(final Resource josmOsmFile, final WritableResource osmFile) { final StringList result = new StringList(); for (final String line : josmOsmFile.lines()) { String replaced = line; for (final Tuple<String, String> replacement : this.replacements) { replaced = replaced.replaceAll(replacement.getFirst(), replacement.getSecond()); } result.add(replaced); } osmFile.writeAndClose(result.join(System.lineSeparator())); } }
public static AtlasStatistics fromResource(final Resource resource) { final AtlasStatistics result = new AtlasStatistics(); resource.lines().forEach(line -> { if (line.startsWith("#")) { return; } final StringList split = StringList.split(line, ","); final StatisticKey key = new StatisticKey(split.get(TAG), split.get(TYPE), split.get(SUB_TYPE)); final StatisticValue value = new StatisticValue(Double.valueOf(split.get(COUNT)), Double.valueOf(split.get(TOTAL))); result.add(key, value); }); return result; }
private void testCount(final String type, final int count) { final Atlas atlas = this.rule.getAtlas(); final List<SimpleCoverage<AtlasEntity>> coverages = new ArrayList<>(); SimpleCoverage.parseSimpleCoverages(atlas, Iterables.filter( Counter.POI_COUNTS_DEFINITION.getDefault().lines(), line -> line.startsWith(type))) .forEach(coverages::add); final SimpleCoverage<AtlasEntity> result = coverages.get(0); result.run(); logger.info("{}", result.getStatistic()); Assert.assertEquals(count, result.getStatistic().values().iterator().next().getCount(), 0.01); } }
for (final String line : resource.lines())
SimpleCoverage.parseSimpleCoverages(atlas, this.countsDefinition.lines()) .forEach(coverages::add); coverages.add(new EdgesCountCoverage(atlas, edge -> HighwayTag.isMetricHighway(edge)
for (final Resource file : files) for (final String line : file.lines())
@Test public void testMultiPolygonBoundary() { final StringList countries = new StringList(); countries.add("ZAF"); final CountryBoundaryMap boundaries = CountryBoundaryMap .fromPlainText(new InputStreamResource(() -> CountryShardListingTest.class .getResourceAsStream("ZAF_osm_boundary.txt.gz")) .withDecompressor(Decompressor.GZIP)); final Sharding sharding = Sharding.forString("dynamic@" + CountryShardListingTest.class.getResource("tree-6-14-100000.txt.gz").getPath()); final MultiMapWithSet<String, Shard> shardSetPerCountry = CountryShardListing .countryToShardList(countries, boundaries, sharding); final Resource expectedShardList = new InputStreamResource( () -> CountryShardListingTest.class .getResourceAsStream("ZAF_osm_shards_with_14.txt")); Assert.assertEquals(Iterables.size(expectedShardList.lines()), shardSetPerCountry.get(countries.get(0)).size()); expectedShardList.lines().forEach(line -> { final CountryShard expected = CountryShard.forName(line); Assert.assertTrue( shardSetPerCountry.get(countries.get(0)).contains(expected.getShard())); }); }
for (final Resource file : files) for (final String line : file.lines())