1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.io.FileInputStream;
|
---|
5 | import java.util.ArrayList;
|
---|
6 | import java.util.Collection;
|
---|
7 | import java.util.Iterator;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import org.fest.reflect.core.Reflection;
|
---|
11 | import org.fest.reflect.reference.TypeRef;
|
---|
12 | import org.junit.Assert;
|
---|
13 | import org.junit.BeforeClass;
|
---|
14 | import org.junit.Test;
|
---|
15 | import org.openstreetmap.josm.Main;
|
---|
16 | import org.openstreetmap.josm.data.Preferences;
|
---|
17 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
18 | import org.openstreetmap.josm.data.projection.Projections;
|
---|
19 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
20 | import org.openstreetmap.josm.io.OsmReader;
|
---|
21 |
|
---|
22 | public class QuadBucketsTest {
|
---|
23 |
|
---|
24 | @BeforeClass
|
---|
25 | public static void init() {
|
---|
26 | Main.initApplicationPreferences();
|
---|
27 | }
|
---|
28 |
|
---|
29 | private void removeAllTest(DataSet ds) {
|
---|
30 | List<Node> allNodes = new ArrayList<Node>(ds.getNodes());
|
---|
31 | List<Way> allWays = new ArrayList<Way>(ds.getWays());
|
---|
32 | List<Relation> allRelations = new ArrayList<Relation>(ds.getRelations());
|
---|
33 |
|
---|
34 | QuadBuckets<Node> nodes = Reflection.field("nodes").ofType(new TypeRef<QuadBuckets<Node>>() {}).in(ds).get();
|
---|
35 | QuadBuckets<Way> ways = Reflection.field("ways").ofType(new TypeRef<QuadBuckets<Way>>() {}).in(ds).get();
|
---|
36 | Collection<Relation> relations = Reflection.field("relations").ofType(new TypeRef<Collection<Relation>>() {}).in(ds).get();
|
---|
37 |
|
---|
38 | int expectedCount = allNodes.size();
|
---|
39 | for (OsmPrimitive o: allNodes) {
|
---|
40 | ds.removePrimitive(o);
|
---|
41 | checkIterator(nodes, --expectedCount);
|
---|
42 | }
|
---|
43 | expectedCount = allWays.size();
|
---|
44 | for (OsmPrimitive o: allWays) {
|
---|
45 | ds.removePrimitive(o);
|
---|
46 | checkIterator(ways, --expectedCount);
|
---|
47 | }
|
---|
48 | for (OsmPrimitive o: allRelations) {
|
---|
49 | ds.removePrimitive(o);
|
---|
50 | }
|
---|
51 | Assert.assertTrue(nodes.isEmpty());
|
---|
52 | Assert.assertTrue(ways.isEmpty());
|
---|
53 | Assert.assertTrue(relations.isEmpty());
|
---|
54 | }
|
---|
55 |
|
---|
56 | private void checkIterator(Collection<? extends OsmPrimitive> col, int expectedCount) {
|
---|
57 | int count = 0;
|
---|
58 | Iterator<? extends OsmPrimitive> it = col.iterator();
|
---|
59 | while (it.hasNext()) {
|
---|
60 | count++;
|
---|
61 | it.next();
|
---|
62 | }
|
---|
63 | Assert.assertEquals(expectedCount, count);
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Test
|
---|
67 | public void testRemove() throws Exception {
|
---|
68 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
|
---|
69 | DataSet ds = OsmReader.parseDataSet(new FileInputStream("data_nodist/restriction.osm"), NullProgressMonitor.INSTANCE);
|
---|
70 | removeAllTest(ds);
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Test
|
---|
74 | public void testMove() throws Exception {
|
---|
75 | Main.setProjection(Projections.getProjectionByCode("EPSG:3857")); // Mercator
|
---|
76 | DataSet ds = OsmReader.parseDataSet(new FileInputStream("data_nodist/restriction.osm"), NullProgressMonitor.INSTANCE);
|
---|
77 |
|
---|
78 | for (Node n: ds.getNodes()) {
|
---|
79 | n.setCoor(new LatLon(10, 10));
|
---|
80 | }
|
---|
81 |
|
---|
82 | removeAllTest(ds);
|
---|
83 | }
|
---|
84 |
|
---|
85 | }
|
---|