source: osm/applications/editors/josm/plugins/utilsplugin/UtilsPlugin/JosmLint/WayCheckTest.java@ 5075

Last change on this file since 5075 was 5075, checked in by gabriel, 18 years ago

Import the latest upstream version of utilsplugin.

File size: 4.2 KB
Line 
1package UtilsPlugin.JosmLint;
2
3import java.util.Collection;
4import java.util.ArrayList;
5
6import org.openstreetmap.josm.data.osm.OsmPrimitive;
7import org.openstreetmap.josm.data.osm.Node;
8import org.openstreetmap.josm.data.osm.Segment;
9import org.openstreetmap.josm.data.osm.Way;
10
11public class WayCheckTest implements JosmLintTest {
12 private class DiscontinuousWayResult extends JosmLintTestResult
13 {
14 public DiscontinuousWayResult( Way o, WayCheckTest c )
15 {
16 super( o, c );
17 }
18 public String toString()
19 {
20 return "Discontinuous way: "+ObjectDescr(obj);
21 }
22 }
23 private class NullWayResult extends JosmLintTestResult
24 {
25 public NullWayResult( Way o, WayCheckTest c )
26 {
27 super( o, c );
28 }
29 public String toString()
30 {
31 return "Null way: "+ObjectDescr(obj);
32 }
33 }
34 private class UnorderedWayResult extends JosmLintTestResult
35 {
36 private Segment seg;
37 public UnorderedWayResult( Way o, WayCheckTest c )
38 {
39 super( o, c );
40 }
41 public String toString()
42 {
43 return "Unordered way: "+ObjectDescr(obj);
44 }
45 }
46 public WayCheckTest() {}
47
48 public JosmLintTestResult runTest( OsmPrimitive o )
49 {
50 if( o instanceof Node )
51 return null;
52 if( o instanceof Segment )
53 return null;
54 if( o instanceof Way )
55 {
56 Way w = (Way)o;
57 if( w.isIncomplete() )
58 return null;
59 if( w.segments.size() == 0 )
60 return new NullWayResult( w, this );
61 boolean unordered = false;
62 ArrayList<Segment> unused = new ArrayList<Segment>(w.segments);
63 Segment s1 = unused.get(0);
64 unused.remove(s1);
65 Node start = s1.from;
66 Node end = s1.to;
67 boolean change = true;
68 while(change)
69 {
70 change = false;
71 ArrayList<Segment> temp = new ArrayList<Segment>(unused);
72 for ( Segment s : temp )
73 {
74 if( s.from == s.to )
75 {
76 unused.remove(s);
77 change = true;
78 continue;
79 }
80 if( s.from == end )
81 {
82 end = s.to;
83 change = true;
84 unused.remove(s);
85 }
86 else if( s.to == start )
87 {
88 start = s.from;
89 unused.remove(s);
90 change = true;
91 unordered = true;
92 }
93 }
94 }
95 if( unused.size() != 0 )
96 {
97 return new DiscontinuousWayResult( w, this );
98 }
99 if( unordered )
100 {
101 return new UnorderedWayResult( w, this );
102 }
103 return null;
104 }
105 return null;
106 }
107}
Note: See TracBrowser for help on using the repository browser.