Changeset 3441 in osm for applications/editors/josm/plugins/validator/src
- Timestamp:
- 2007-07-01T22:31:02+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/SingleNodeSegment.java
r2591 r3441 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import org.openstreetmap.josm.command.Command; 6 import org.openstreetmap.josm.command.DeleteCommand; 5 import java.util.ArrayList; 6 import java.util.Arrays; 7 import java.util.List; 8 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.command.*; 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 12 import org.openstreetmap.josm.data.osm.Segment; 13 import org.openstreetmap.josm.data.osm.Way; 14 import org.openstreetmap.josm.data.osm.visitor.CollectBackReferencesVisitor; 15 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 8 16 import org.openstreetmap.josm.plugins.validator.Severity; 9 17 import org.openstreetmap.josm.plugins.validator.Test; … … 19 27 /** Tags allowed in a segment */ 20 28 public static String[] allowedTags = new String[] { "created_by" }; 29 21 30 /** 22 31 * Constructor … … 40 49 public Command fixError(TestError testError) 41 50 { 42 return new DeleteCommand(testError.getPrimitives()); 51 if( testError.getPrimitives().isEmpty() ) 52 return null; 53 54 Segment s = (Segment)testError.getPrimitives().get(0); 55 if( s.deleted ) 56 return null; 57 58 List<Command> cmds = new ArrayList<Command>(); 59 cmds.add(new DeleteCommand(testError.getPrimitives())); 60 61 CollectBackReferencesVisitor refV = new CollectBackReferencesVisitor(Main.ds); 62 s.visit(refV); 63 64 for(OsmPrimitive p : refV.data) 65 { 66 if( p.deleted ) 67 continue; 68 69 Way newway = new Way((Way)p); 70 if( newway.segments.remove(s) ) // Made changes? 71 { 72 // If no segments left, delete the way 73 if( newway.segments.size() == 0 ) 74 cmds.add(new DeleteCommand(Arrays.asList(new OsmPrimitive[]{p}))); 75 else 76 cmds.add(new ChangeCommand(p, newway)); 77 } 78 } 79 80 if( cmds.size() == 1 ) // Segment wasn't in any way 81 return (Command)cmds.get(0); 82 83 NameVisitor nameV = new NameVisitor(); 84 s.visit(nameV); 85 return new SequenceCommand(tr("Delete")+" "+tr(nameV.className)+" "+nameV.name, cmds); 43 86 } 44 87 … … 47 90 { 48 91 return (testError.getTester() instanceof SingleNodeSegment); 49 } 92 } 50 93 }
Note:
See TracChangeset
for help on using the changeset viewer.