source: josm/test/unit/org/openstreetmap/josm/testframework/DataSetTestCaseHelper.java@ 298

Last change on this file since 298 was 298, checked in by imi, 17 years ago
  • added license description to head of each source file
File size: 1.9 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.testframework;
3
4import java.util.Arrays;
5
6import org.openstreetmap.josm.Main;
7import org.openstreetmap.josm.data.coor.LatLon;
8import org.openstreetmap.josm.data.osm.DataSet;
9import org.openstreetmap.josm.data.osm.Segment;
10import org.openstreetmap.josm.data.osm.Node;
11import org.openstreetmap.josm.data.osm.Way;
12import org.openstreetmap.josm.data.projection.Mercator;
13
14
15/**
16 * Test cases that need to manupulate a data set can use this helper.
17 *
18 * @author Imi
19 */
20public class DataSetTestCaseHelper {
21
22 /**
23 * Create a common dataset consisting of:
24 * - 5 random nodes
25 * - ls between node 0 and 1
26 * - ls between node 1 and 2
27 * - ls between node 3 and 4
28 * - a way with ls 0 and 1
29 */
30 public static DataSet createCommon() {
31 DataSet ds = new DataSet();
32 Node n1 = createNode(ds);
33 Node n2 = createNode(ds);
34 Node n3 = createNode(ds);
35 Node n4 = createNode(ds);
36 Node n5 = createNode(ds);
37 Segment ls1 = createSegment(ds, n1, n2);
38 Segment ls2 = createSegment(ds, n2, n3);
39 createSegment(ds, n4, n5);
40 createWay(ds, ls1, ls2);
41 return ds;
42 }
43
44 public static Way createWay(DataSet ds, Segment... segments) {
45 Way w = new Way();
46 w.segments.addAll(Arrays.asList(segments));
47 if (ds != null)
48 ds.ways.add(w);
49 return w;
50 }
51
52 /**
53 * Create a segment with out of the given nodes.
54 */
55 public static Segment createSegment(DataSet ds, Node n1, Node n2) {
56 Segment ls = new Segment(n1, n2);
57 if (ds != null)
58 ds.segments.add(ls);
59 return ls;
60 }
61
62 /**
63 * Add a random node.
64 */
65 public static Node createNode(DataSet ds) {
66 if (Main.proj == null)
67 Main.proj = new Mercator();
68 Node node = new Node(new LatLon(Math.random(), Math.random()));
69 if (ds != null)
70 ds.nodes.add(node);
71 return node;
72 }
73
74}
Note: See TracBrowser for help on using the repository browser.