org.openstreetmap.atlas.geography.boundary.CountryBoundaryMapCompareCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atlas Show documentation
Show all versions of atlas Show documentation
"Library to load OSM data into an Atlas format"
package org.openstreetmap.atlas.geography.boundary;
import java.util.Set;
import org.junit.Assert;
import org.openstreetmap.atlas.streaming.resource.File;
import org.openstreetmap.atlas.utilities.runtime.Command;
import org.openstreetmap.atlas.utilities.runtime.CommandMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Compares given {@link CountryBoundaryMap}s to find if there are any differences between them.
*
* @author mkalender
*/
public class CountryBoundaryMapCompareCommand extends Command
{
private static final Logger logger = LoggerFactory
.getLogger(CountryBoundaryMapCompareCommand.class);
// Parameters
private static final Switch BASELINE_MAP = new Switch<>("baseline",
"Path to file generated by CountryBoundaryMap to use as a baseline",
path -> CountryBoundaryMap.fromPlainText(new File(path)), Optionality.REQUIRED);
private static final Switch OTHER_MAP = new Switch<>("new",
"Path to file generated by CountryBoundaryMap to compare against baseline",
path -> CountryBoundaryMap.fromPlainText(new File(path)), Optionality.REQUIRED);
public static void main(final String[] args)
{
new CountryBoundaryMapCompareCommand().run(args);
}
@Override
protected int onRun(final CommandMap command)
{
// Read inputs
final CountryBoundaryMap baselineMap = (CountryBoundaryMap) command.get(BASELINE_MAP);
final CountryBoundaryMap newMap = (CountryBoundaryMap) command.get(OTHER_MAP);
// Compare loaded countries
final Set baselineCountries = baselineMap.getLoadedCountries();
final Set newCountries = newMap.getLoadedCountries();
baselineCountries.forEach(country -> Assert.assertTrue(
String.format("New map is missing country %s.", country),
newCountries.contains(country)));
newCountries.forEach(country -> Assert.assertTrue(
String.format("New map has additional country %s.", country),
baselineCountries.contains(country)));
Assert.assertEquals("Map sizes are not equal.", baselineMap.size(), newMap.size());
// Compare country boundaries
baselineMap.getLoadedCountries().forEach(country -> baselineMap.countryBoundary(country)
.forEach(countryBoundary -> Assert.assertTrue(
String.format("New map is missing a boundary for %s.", country),
newMap.countryBoundary(country).contains(countryBoundary.getBoundary()))));
newMap.getLoadedCountries()
.forEach(country -> newMap.countryBoundary(country)
.forEach(countryBoundary -> Assert.assertTrue(
String.format("New map is missing a boundary for %s.", country),
baselineMap.countryBoundary(country)
.contains(countryBoundary.getBoundary()))));
logger.info("Compared given maps and found no difference.");
return 0;
}
@Override
protected SwitchList switches()
{
return new SwitchList().with(BASELINE_MAP, OTHER_MAP);
}
}