1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.testutils;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
5 | import org.openstreetmap.josm.data.osm.Node;
|
---|
6 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
7 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
8 | import org.openstreetmap.josm.data.osm.Way;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Convenience class allowing to manage primitives in the dataset. Useful especially for tests
|
---|
12 | */
|
---|
13 | public class DatasetFactory {
|
---|
14 |
|
---|
15 | private final DataSet ds;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Constructs a new {@code DatasetFactory} with a new dataset.
|
---|
19 | */
|
---|
20 | public DatasetFactory() {
|
---|
21 | this(new DataSet());
|
---|
22 | }
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Constructs a new {@code DatasetFactory} with a given dataset.
|
---|
26 | * @param ds existing dataset to wrap
|
---|
27 | */
|
---|
28 | public DatasetFactory(DataSet ds) {
|
---|
29 | this.ds = ds;
|
---|
30 | }
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Replies node with given id.
|
---|
34 | * @param id node id
|
---|
35 | * @return node with given id
|
---|
36 | */
|
---|
37 | public Node getNode(long id) {
|
---|
38 | return (Node) ds.getPrimitiveById(id, OsmPrimitiveType.NODE);
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Replies way with given id.
|
---|
43 | * @param id way id
|
---|
44 | * @return way with given id
|
---|
45 | */
|
---|
46 | public Way getWay(long id) {
|
---|
47 | return (Way) ds.getPrimitiveById(id, OsmPrimitiveType.WAY);
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Replies relation with given id.
|
---|
52 | * @param id relation id
|
---|
53 | * @return relation with given id
|
---|
54 | */
|
---|
55 | public Relation getRelation(long id) {
|
---|
56 | return (Relation) ds.getPrimitiveById(id, OsmPrimitiveType.RELATION);
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Adds node with given id.
|
---|
61 | * @param id node id
|
---|
62 | * @return created node
|
---|
63 | */
|
---|
64 | public Node addNode(long id) {
|
---|
65 | return addNode(id, 0);
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Adds way with given id.
|
---|
70 | * @param id way id
|
---|
71 | * @return created way
|
---|
72 | */
|
---|
73 | public Way addWay(long id) {
|
---|
74 | return addWay(id, 0);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Adds relation with given id.
|
---|
79 | * @param id relation id
|
---|
80 | * @return created relation
|
---|
81 | */
|
---|
82 | public Relation addRelation(long id) {
|
---|
83 | return addRelation(id, 0);
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Adds node with given id and version.
|
---|
88 | * @param id node id
|
---|
89 | * @param version node version
|
---|
90 | * @return created node
|
---|
91 | */
|
---|
92 | public Node addNode(long id, int version) {
|
---|
93 | Node n = new Node(id, version);
|
---|
94 | ds.addPrimitive(n);
|
---|
95 | return n;
|
---|
96 | }
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Adds way with given id and version.
|
---|
100 | * @param id way id
|
---|
101 | * @param version way version
|
---|
102 | * @return created way
|
---|
103 | */
|
---|
104 | public Way addWay(long id, int version) {
|
---|
105 | Way w = new Way(id, version);
|
---|
106 | ds.addPrimitive(w);
|
---|
107 | return w;
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Adds relation with given id and version.
|
---|
112 | * @param id relation id
|
---|
113 | * @param version relation version
|
---|
114 | * @return created relation
|
---|
115 | */
|
---|
116 | public Relation addRelation(long id, int version) {
|
---|
117 | Relation e = new Relation(id, version);
|
---|
118 | ds.addPrimitive(e);
|
---|
119 | return e;
|
---|
120 | }
|
---|
121 | }
|
---|