1 | package UtilsPlugin.JosmLint;
|
---|
2 |
|
---|
3 | import java.util.Collection;
|
---|
4 | import java.util.ArrayList;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
7 | import org.openstreetmap.josm.data.osm.Node;
|
---|
8 | import org.openstreetmap.josm.data.osm.Segment;
|
---|
9 | import org.openstreetmap.josm.data.osm.Way;
|
---|
10 |
|
---|
11 | public 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 | }
|
---|