Changeset 5199 in josm for trunk/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java
- Timestamp:
- 2012-04-17T21:03:50+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java
r4806 r5199 11 11 import org.openstreetmap.josm.data.osm.Node; 12 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 import org.openstreetmap.josm.data.osm.OsmUtils;14 13 import org.openstreetmap.josm.data.osm.Relation; 15 14 import org.openstreetmap.josm.data.osm.RelationMember; … … 35 34 protected static final int MIX_VIA = 1813; 36 35 protected static final int UNCONNECTED_VIA = 1814; 36 protected static final int SUPERFLUOUS = 1815; 37 37 38 38 public TurnrestrictionTest() { … … 137 137 } 138 138 139 Node viaNode;140 139 if (via.get(0) instanceof Node) { 141 viaNode = (Node) via.get(0);142 Way viaPseudoWay = new Way();140 final Node viaNode = (Node) via.get(0); 141 final Way viaPseudoWay = new Way(); 143 142 viaPseudoWay.addNode(viaNode); 144 143 checkIfConnected(fromWay, viaPseudoWay, 145 144 tr("The \"from\" way does not start or end at a \"via\" node"), FROM_VIA_NODE); 145 if (toWay.isOneway() != 0 && viaNode.equals(toWay.lastNode(true))) { 146 errors.add(new TestError(this, Severity.WARNING, tr("Superfluous turnrestriction as \"to\" way is oneway"), SUPERFLUOUS, r)); 147 return; 148 } 146 149 checkIfConnected(viaPseudoWay, toWay, 147 150 tr("The \"to\" way does not start or end at a \"via\" node"), TO_VIA_NODE); 148 151 } else { 149 152 // check if consecutive ways are connected: from/via[0], via[i-1]/via[i], via[last]/to 150 checkIfConnected(fromWay, (Way) via.get(0), 153 checkIfConnected(fromWay, (Way) via.get(0), 151 154 tr("The \"from\" and the first \"via\" way are not connected."), FROM_VIA_WAY); 152 155 if (via.size() > 1) { … … 158 161 } 159 162 } 163 if (toWay.isOneway() != 0 && ((Way) via.get(via.size() - 1)).isFirstLastNode(toWay.lastNode(true))) { 164 errors.add(new TestError(this, Severity.WARNING, tr("Superfluous turnrestriction as \"to\" way is oneway"), SUPERFLUOUS, r)); 165 return; 166 } 160 167 checkIfConnected((Way) via.get(via.size() - 1), toWay, 161 168 tr("The last \"via\" and the \"to\" way are not connected."), TO_VIA_WAY); … … 165 172 166 173 private void checkIfConnected(Way previous, Way current, String msg, int code) { 167 int onewayPrevious = isOneway(previous);168 int onewayCurrent = isOneway(current);169 Node endPrevious = onewayPrevious != -1 ? previous.lastNode() : previous.firstNode();170 Node startCurrent = onewayCurrent != -1 ? current.firstNode() : current.lastNode();171 //System.out.println(previous.getUniqueId() + " -- " + current.getUniqueId() + ": " + onewayPrevious + "/" + onewayCurrent + " " + endPrevious.getUniqueId() + "/" + startCurrent.getUniqueId());172 174 boolean c; 173 if ( onewayPrevious != 0 && onewayCurrent!= 0) {175 if (previous.isOneway() != 0 && current.isOneway() != 0) { 174 176 // both oneways: end/start node must be equal 175 c = endPrevious.equals(startCurrent);176 } else if ( onewayPrevious!= 0) {177 c = previous.lastNode(true).equals(current.firstNode(true)); 178 } else if (previous.isOneway() != 0) { 177 179 // previous way is oneway: end of previous must be start/end of current 178 c = current.isFirstLastNode( endPrevious);179 } else if ( onewayCurrent!= 0) {180 c = current.isFirstLastNode(previous.lastNode(true)); 181 } else if (current.isOneway() != 0) { 180 182 // current way is oneway: start of current must be start/end of previous 181 c = previous.isFirstLastNode( startCurrent);183 c = previous.isFirstLastNode(current.firstNode(true)); 182 184 } else { 183 185 // otherwise: start/end of previous must be start/end of current … … 188 190 } 189 191 } 190 191 private static int isOneway(Way w) {192 String onewayviastr = w.get("oneway");193 if (onewayviastr != null) {194 if ("-1".equals(onewayviastr)) {195 return -1;196 } else {197 Boolean onewayvia = OsmUtils.getOsmBoolean(onewayviastr);198 if (onewayvia != null && onewayvia) {199 return 1;200 }201 }202 }203 return 0;204 }205 192 }
Note:
See TracChangeset
for help on using the changeset viewer.