Hi,
here is a small update of the TagCorrector. Some code cleanup and
addition of the key prefixes/suffixes "forward" and "backward".
Robin
Index: src/org/openstreetmap/josm/actions/ReverseWayAction.java
===
--- src/org/openstreetmap/josm/actions/ReverseWayAction.java(revision 743)
+++ src/org/openstreetmap/josm/actions/ReverseWayAction.java(working copy)
@@ -16,6 +16,7 @@
import org.openstreetmap.josm.command.Command;
import org.openstreetmap.josm.command.SequenceCommand;
import org.openstreetmap.josm.corrector.ReverseWayTagCorrector;
+import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Relation;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -60,7 +61,7 @@
}
Main.main.undoRedo.add(new SequenceCommand(tr("Reverse ways"),
c));
if (propertiesUpdated)
- Main.ds.fireSelectionChanged(Main.ds.getSelected());
+ DataSet.fireSelectionChanged(Main.ds.getSelected());
Main.map.repaint();
}
}
Index: src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java
===
--- src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java
(revision 743)
+++ src/org/openstreetmap/josm/corrector/ReverseWayTagCorrector.java
(working copy)
@@ -9,15 +9,48 @@
import org.openstreetmap.josm.data.osm.OsmUtils;
import org.openstreetmap.josm.data.osm.Way;
+import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
public class ReverseWayTagCorrector extends TagCorrector {
- private static final Pattern leftRightStartRegex = Pattern.compile(
- "^(left|right):.*", Pattern.CASE_INSENSITIVE);
+ private static class PrefixSuffixSwitcher {
- private static final Pattern leftRightEndRegex = Pattern.compile(
- ".*:(left|right)$", Pattern.CASE_INSENSITIVE);
+ private final String a;
+ private final String b;
+ private final Pattern startPattern;
+ private final Pattern endPattern;
+
+ public PrefixSuffixSwitcher(String a, String b) {
+ this.a = a;
+ this.b = b;
+ startPattern = Pattern.compile("^(" + a + "|" + b +
"):.*",
+ Pattern.CASE_INSENSITIVE);
+ endPattern = Pattern.compile(".*:(" + a + "|" + b +
")$",
+ Pattern.CASE_INSENSITIVE);
+ }
+
+ public String apply(String text) {
+ Matcher m = startPattern.matcher(text);
+ if (!m.matches())
+ m = endPattern.matcher(text);
+
+ if (m.matches()) {
+ String leftRight = m.group(1).toLowerCase();
+
+ return text.substring(0, m.start(1)).concat(
+ leftRight.equals(a) ? b : a).concat(
+ text.substring(m.end(1)));
+ }
+ return text;
+ }
+ }
+
+ private static PrefixSuffixSwitcher[] prefixSuffixSwitchers = new
PrefixSuffixSwitcher[] {
+ new PrefixSuffixSwitcher("left", "right"),
+ new PrefixSuffixSwitcher("forward", "backward")
+ };
+
@Override public boolean execute(Way way) {
ArrayList tagCorrections = new
ArrayList();
@@ -37,27 +70,26 @@
}
}
} else {
- Matcher m = leftRightStartRegex.matcher(key);
- if (!m.matches())
- m = leftRightEndRegex.matcher(key);
-
- if (m.matches()) {
- String leftRight =
m.group(1).toLowerCase();
-
- newKey = key.substring(0,
m.start(1)).concat(
- leftRight.equals("left") ?
"right" : "left")
-
.concat(key.substring(m.end(1)));
- }
+ for (PrefixSuffixSwitcher prefixSuffixSwitcher
: prefixSuffixSwitchers) {
+ newKey =
prefixSuffixSwitcher.apply(key);
+ if (!key.equals(newKey))
+ break;
+}
}
- if (key != newKey || value != newValue)
+ if (!key.equals(newKey) || !value.equals(n