// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.corrector;
import static org.openstreetmap.josm.tools.I18n.tr;
import static org.openstreetmap.josm.tools.I18n.trn;
import java.util.Arrays;
import javax.swing.JOptionPane;
import org.openstreetmap.josm.Main;
import org.openstreetmap.josm.data.osm.Tag;
import org.openstreetmap.josm.data.osm.TagCollection;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
import org.openstreetmap.josm.gui.DefaultNameFormatter;
/**
* A ReverseWayNoTagCorrector warns about ways that should not be reversed
* because their semantic meaning cannot be preserved in that case.
* E.g. natural=coastline, natural=cliff, barrier=retaining_wall cannot be changed.
* @see ReverseWayTagCorrector for handling of tags that can be modified (oneway=yes, etc.)
* @since 5724
*/
public class ReverseWayNoTagCorrector {
/**
* Tags that imply a semantic meaning from the way direction and cannot be changed.
*/
public static final TagCollection directionalTags = new TagCollection(Arrays.asList(new Tag[]{
new Tag("natural", "coastline"),
new Tag("natural", "cliff"),
new Tag("barrier", "guard_rail"),
new Tag("barrier", "kerb"),
new Tag("barrier", "retaining_wall"),
new Tag("waterway", "stream"),
new Tag("waterway", "river"),
new Tag("waterway", "ditch"),
new Tag("waterway", "drain"),
new Tag("waterway", "canal")
}));
/**
* Replies the tags that imply a semantic meaning from way
direction and cannot be changed.
* @param way The way to look for
* @return tags that imply a semantic meaning from way
direction and cannot be changed
*/
public static final TagCollection getDirectionalTags(Way way) {
return directionalTags.intersect(TagCollection.from(way));
}
/**
* Tests whether way can be reversed without semantic change.
* Looks for tags like natural=cliff, barrier=retaining_wall.
* @param way The way to check
* @return false if the semantic meaning change if the way is reversed, true otherwise.
*/
public static boolean isReversible(Way way) {
return getDirectionalTags(way).isEmpty();
}
protected static String getHTML(TagCollection tags) {
if (tags.size() == 1) {
return tags.iterator().next().toString();
} else if (tags.size() > 1) {
StringBuilder s = new StringBuilder("