1 | package org.openstreetmap.josm.test.framework;
|
---|
2 |
|
---|
3 | import java.util.Arrays;
|
---|
4 |
|
---|
5 | import org.openstreetmap.josm.data.GeoPoint;
|
---|
6 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
7 | import org.openstreetmap.josm.data.osm.LineSegment;
|
---|
8 | import org.openstreetmap.josm.data.osm.Node;
|
---|
9 | import org.openstreetmap.josm.data.osm.Way;
|
---|
10 |
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Test cases that need to manupulate a data set can use this helper.
|
---|
14 | *
|
---|
15 | * @author Imi
|
---|
16 | */
|
---|
17 | public class DataSetTestCaseHelper {
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Create a common dataset consisting of:
|
---|
21 | * - 5 random nodes
|
---|
22 | * - ls between node 0 and 1
|
---|
23 | * - ls between node 1 and 2
|
---|
24 | * - ls between node 3 and 4
|
---|
25 | * - a way with ls 0 and 1
|
---|
26 | */
|
---|
27 | public static DataSet createCommon() {
|
---|
28 | DataSet ds = new DataSet();
|
---|
29 | Node n1 = createNode(ds);
|
---|
30 | Node n2 = createNode(ds);
|
---|
31 | Node n3 = createNode(ds);
|
---|
32 | Node n4 = createNode(ds);
|
---|
33 | Node n5 = createNode(ds);
|
---|
34 | LineSegment ls1 = createLineSegment(ds, n1, n2);
|
---|
35 | LineSegment ls2 = createLineSegment(ds, n2, n3);
|
---|
36 | createLineSegment(ds, n4, n5);
|
---|
37 | createWay(ds, ls1, ls2);
|
---|
38 | return ds;
|
---|
39 | }
|
---|
40 |
|
---|
41 | public static Way createWay(DataSet ds, LineSegment... lineSegments) {
|
---|
42 | Way t = new Way();
|
---|
43 | t.segments.addAll(Arrays.asList(lineSegments));
|
---|
44 | ds.waies.add(t);
|
---|
45 | return t;
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Create a line segment with out of the given nodes.
|
---|
50 | */
|
---|
51 | public static LineSegment createLineSegment(DataSet ds, Node n1, Node n2) {
|
---|
52 | LineSegment ls = new LineSegment(n1, n2);
|
---|
53 | ds.lineSegments.add(ls);
|
---|
54 | return ls;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Add a random node.
|
---|
59 | */
|
---|
60 | public static Node createNode(DataSet ds) {
|
---|
61 | Node node = new Node(new GeoPoint(Math.random(), Math.random()));
|
---|
62 | ds.nodes.add(node);
|
---|
63 | return node;
|
---|
64 | }
|
---|
65 |
|
---|
66 | }
|
---|