source: josm/trunk/src/org/openstreetmap/josm/data/osm/OsmData.java@ 13806

Last change on this file since 13806 was 13766, checked in by Don-vip, 6 years ago

API alignment between Relation/RelationData and RelationMember/RelationMemberData: update of IRelation/IRelationMember interfaces

  • Property svn:eol-style set to native
File size: 15.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.util.Collection;
5import java.util.List;
6import java.util.concurrent.locks.Lock;
7import java.util.function.Predicate;
8
9import org.openstreetmap.josm.data.Data;
10import org.openstreetmap.josm.data.DataSource;
11import org.openstreetmap.josm.data.ProjectionBounds;
12import org.openstreetmap.josm.data.SelectionChangedListener;
13import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
14import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
15
16/**
17 * Abstraction of {@link DataSet}.
18 * This class holds OSM data but does not rely on implementation types,
19 * allowing plugins to define their own representation of OSM data if needed.
20 * @param <O> the base type of OSM primitives
21 * @param <N> type representing OSM nodes
22 * @param <W> type representing OSM ways
23 * @param <R> type representing OSM relations
24 * @since 13764
25 */
26public interface OsmData<O extends IPrimitive, N extends INode, W extends IWay<N>, R extends IRelation<?>> extends Data, Lockable {
27
28 // --------------
29 // Metadata
30 // --------------
31
32 /**
33 * Replies the API version this dataset was created from. May be null.
34 * @return the API version this dataset was created from. May be null.
35 */
36 String getVersion();
37
38 /**
39 * Returns the name of this data set (optional).
40 * @return the name of this data set. Can be {@code null}
41 * @since 12718
42 */
43 String getName();
44
45 /**
46 * Sets the name of this data set.
47 * @param name the new name of this data set. Can be {@code null} to reset it
48 * @since 12718
49 */
50 void setName(String name);
51
52 // --------------------
53 // OSM primitives
54 // --------------------
55
56 /**
57 * Adds a primitive.
58 * @param primitive the primitive
59 */
60 void addPrimitive(O primitive);
61
62 /**
63 * Removes all primitives.
64 */
65 void clear();
66
67 /**
68 * Searches for nodes in the given bounding box.
69 * @param bbox the bounding box
70 * @return List of nodes in the given bbox. Can be empty but not null
71 */
72 List<N> searchNodes(BBox bbox);
73
74 /**
75 * Determines if the given node can be retrieved in the data set through its bounding box. Useful for dataset consistency test.
76 * @param n The node to search
77 * @return {@code true} if {@code n} can be retrieved in this data set, {@code false} otherwise
78 */
79 boolean containsNode(N n);
80
81 /**
82 * Searches for ways in the given bounding box.
83 * @param bbox the bounding box
84 * @return List of ways in the given bbox. Can be empty but not null
85 */
86 List<W> searchWays(BBox bbox);
87
88 /**
89 * Determines if the given way can be retrieved in the data set through its bounding box. Useful for dataset consistency test.
90 * @param w The way to search
91 * @return {@code true} if {@code w} can be retrieved in this data set, {@code false} otherwise
92 */
93 boolean containsWay(W w);
94
95 /**
96 * Searches for relations in the given bounding box.
97 * @param bbox the bounding box
98 * @return List of relations in the given bbox. Can be empty but not null
99 */
100 List<R> searchRelations(BBox bbox);
101
102 /**
103 * Determines if the given relation can be retrieved in the data set through its bounding box. Useful for dataset consistency test.
104 * @param r The relation to search
105 * @return {@code true} if {@code r} can be retrieved in this data set, {@code false} otherwise
106 */
107 boolean containsRelation(R r);
108
109 /**
110 * Returns a primitive with a given id from the data set. null, if no such primitive exists
111 *
112 * @param id uniqueId of the primitive. Might be &lt; 0 for newly created primitives
113 * @param type the type of the primitive. Must not be null.
114 * @return the primitive
115 * @throws NullPointerException if type is null
116 */
117 O getPrimitiveById(long id, OsmPrimitiveType type);
118
119 /**
120 * Returns a primitive with a given id from the data set. null, if no such primitive exists
121 *
122 * @param primitiveId type and uniqueId of the primitive. Might be &lt; 0 for newly created primitives
123 * @return the primitive
124 */
125 O getPrimitiveById(PrimitiveId primitiveId);
126
127 /**
128 * Gets a filtered collection of primitives matching the given predicate.
129 * @param <T> The primitive type.
130 * @param predicate The predicate to match
131 * @return The list of primtives.
132 * @since 10590
133 */
134 <T extends O> Collection<T> getPrimitives(Predicate<? super O> predicate);
135
136 /**
137 * Replies an unmodifiable collection of nodes in this dataset
138 *
139 * @return an unmodifiable collection of nodes in this dataset
140 */
141 Collection<N> getNodes();
142
143 /**
144 * Replies an unmodifiable collection of ways in this dataset
145 *
146 * @return an unmodifiable collection of ways in this dataset
147 */
148 Collection<W> getWays();
149
150 /**
151 * Replies an unmodifiable collection of relations in this dataset
152 *
153 * @return an unmodifiable collection of relations in this dataset
154 */
155 Collection<R> getRelations();
156
157 /**
158 * Returns a collection containing all primitives of the dataset.
159 * @return A collection containing all primitives of the dataset. Data is not ordered
160 */
161 default Collection<O> allPrimitives() {
162 return getPrimitives(o -> true);
163 }
164
165 /**
166 * Returns a collection containing all not-deleted primitives.
167 * @return A collection containing all not-deleted primitives.
168 * @see OsmPrimitive#isDeleted
169 */
170 default Collection<O> allNonDeletedPrimitives() {
171 return getPrimitives(p -> !p.isDeleted());
172 }
173
174 /**
175 * Returns a collection containing all not-deleted complete primitives.
176 * @return A collection containing all not-deleted complete primitives.
177 * @see OsmPrimitive#isDeleted
178 * @see OsmPrimitive#isIncomplete
179 */
180 default Collection<O> allNonDeletedCompletePrimitives() {
181 return getPrimitives(primitive -> !primitive.isDeleted() && !primitive.isIncomplete());
182 }
183
184 /**
185 * Returns a collection containing all not-deleted complete physical primitives.
186 * @return A collection containing all not-deleted complete physical primitives (nodes and ways).
187 * @see OsmPrimitive#isDeleted
188 * @see OsmPrimitive#isIncomplete
189 */
190 default Collection<O> allNonDeletedPhysicalPrimitives() {
191 return getPrimitives(
192 primitive -> !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof IRelation));
193 }
194
195 /**
196 * Returns a collection containing all modified primitives.
197 * @return A collection containing all modified primitives.
198 * @see OsmPrimitive#isModified
199 */
200 default Collection<O> allModifiedPrimitives() {
201 return getPrimitives(IPrimitive::isModified);
202 }
203
204 /**
205 * Returns a collection containing all primitives preserved from filtering.
206 * @return A collection containing all primitives preserved from filtering.
207 * @see OsmPrimitive#isPreserved
208 * @since 13309
209 */
210 default Collection<O> allPreservedPrimitives() {
211 return getPrimitives(IPrimitive::isPreserved);
212 }
213
214 // --------------
215 // Policies
216 // --------------
217
218 /**
219 * Get the download policy.
220 * @return the download policy
221 * @see #setDownloadPolicy(DownloadPolicy)
222 * @since 13453
223 */
224 DownloadPolicy getDownloadPolicy();
225
226 /**
227 * Sets the download policy.
228 * @param downloadPolicy the download policy
229 * @see #getUploadPolicy()
230 * @since 13453
231 */
232 void setDownloadPolicy(DownloadPolicy downloadPolicy);
233
234 /**
235 * Get the upload policy.
236 * @return the upload policy
237 * @see #setUploadPolicy(UploadPolicy)
238 */
239 UploadPolicy getUploadPolicy();
240
241 /**
242 * Sets the upload policy.
243 * @param uploadPolicy the upload policy
244 * @see #getUploadPolicy()
245 */
246 void setUploadPolicy(UploadPolicy uploadPolicy);
247
248 // --------------
249 // Locks
250 // --------------
251
252 /**
253 * Returns the lock used for reading.
254 * @return the lock used for reading
255 */
256 Lock getReadLock();
257
258 // ---------------
259 // Highlight
260 // ---------------
261
262 /**
263 * Returns an unmodifiable collection of *WaySegments* whose virtual
264 * nodes should be highlighted. WaySegments are used to avoid having
265 * to create a VirtualNode class that wouldn't have much purpose otherwise.
266 *
267 * @return unmodifiable collection of WaySegments
268 */
269 Collection<WaySegment> getHighlightedVirtualNodes();
270
271 /**
272 * Returns an unmodifiable collection of WaySegments that should be highlighted.
273 *
274 * @return unmodifiable collection of WaySegments
275 */
276 Collection<WaySegment> getHighlightedWaySegments();
277
278 /**
279 * clear all highlights of virtual nodes
280 */
281 void clearHighlightedVirtualNodes();
282
283 /**
284 * clear all highlights of way segments
285 */
286 void clearHighlightedWaySegments();
287
288 /**
289 * set what virtual nodes should be highlighted. Requires a Collection of
290 * *WaySegments* to avoid a VirtualNode class that wouldn't have much use otherwise.
291 * @param waySegments Collection of way segments
292 */
293 void setHighlightedVirtualNodes(Collection<WaySegment> waySegments);
294
295 /**
296 * set what virtual ways should be highlighted.
297 * @param waySegments Collection of way segments
298 */
299 void setHighlightedWaySegments(Collection<WaySegment> waySegments);
300
301 /**
302 * Adds a listener that gets notified whenever way segment / virtual nodes highlights change.
303 * @param listener The Listener
304 * @since 12014
305 */
306 void addHighlightUpdateListener(HighlightUpdateListener listener);
307
308 /**
309 * Removes a listener that was added with {@link #addHighlightUpdateListener(HighlightUpdateListener)}
310 * @param listener The Listener
311 * @since 12014
312 */
313 void removeHighlightUpdateListener(HighlightUpdateListener listener);
314
315 // ---------------
316 // Selection
317 // ---------------
318
319 /**
320 * Replies an unmodifiable collection of primitives currently selected
321 * in this dataset, except deleted ones. May be empty, but not null.
322 *
323 * When iterating through the set it is ordered by the order in which the primitives were added to the selection.
324 *
325 * @return unmodifiable collection of primitives
326 */
327 Collection<O> getSelected();
328
329 /**
330 * Replies an unmodifiable collection of primitives currently selected
331 * in this dataset, including deleted ones. May be empty, but not null.
332 *
333 * When iterating through the set it is ordered by the order in which the primitives were added to the selection.
334 *
335 * @return unmodifiable collection of primitives
336 */
337 Collection<O> getAllSelected();
338
339 /**
340 * Returns selected nodes.
341 * @return selected nodes
342 */
343 Collection<N> getSelectedNodes();
344
345 /**
346 * Returns selected ways.
347 * @return selected ways
348 */
349 Collection<W> getSelectedWays();
350
351 /**
352 * Returns selected relations.
353 * @return selected relations
354 */
355 Collection<R> getSelectedRelations();
356
357 /**
358 * Determines whether the selection is empty or not
359 * @return whether the selection is empty or not
360 */
361 boolean selectionEmpty();
362
363 /**
364 * Determines whether the given primitive is selected or not
365 * @param osm the primitive
366 * @return whether {@code osm} is selected or not
367 */
368 boolean isSelected(O osm);
369
370 /**
371 * Toggles the selected state of the given collection of primitives.
372 * @param osm The primitives to toggle
373 */
374 void toggleSelected(Collection<? extends PrimitiveId> osm);
375
376 /**
377 * Toggles the selected state of the given collection of primitives.
378 * @param osm The primitives to toggle
379 */
380 void toggleSelected(PrimitiveId... osm);
381
382 /**
383 * Sets the current selection to the primitives in <code>selection</code>
384 * and notifies all {@link SelectionChangedListener}.
385 *
386 * @param selection the selection
387 */
388 void setSelected(Collection<? extends PrimitiveId> selection);
389
390 /**
391 * Sets the current selection to the primitives in <code>osm</code>
392 * and notifies all {@link SelectionChangedListener}.
393 *
394 * @param osm the primitives to set. <code>null</code> values are ignored for now, but this may be removed in the future.
395 */
396 void setSelected(PrimitiveId... osm);
397
398 /**
399 * Adds the primitives in <code>selection</code> to the current selection
400 * and notifies all {@link SelectionChangedListener}.
401 *
402 * @param selection the selection
403 */
404 void addSelected(Collection<? extends PrimitiveId> selection);
405
406 /**
407 * Adds the primitives in <code>osm</code> to the current selection
408 * and notifies all {@link SelectionChangedListener}.
409 *
410 * @param osm the primitives to add
411 */
412 void addSelected(PrimitiveId... osm);
413
414 /**
415 * Removes the selection from every value in the collection.
416 * @param osm The collection of ids to remove the selection from.
417 */
418 void clearSelection(PrimitiveId... osm);
419
420 /**
421 * Removes the selection from every value in the collection.
422 * @param list The collection of ids to remove the selection from.
423 */
424 void clearSelection(Collection<? extends PrimitiveId> list);
425
426 /**
427 * Clears the current selection.
428 */
429 void clearSelection();
430
431 /**
432 * Add a listener that listens to selection changes in this specific data set.
433 * @param listener The listener.
434 * @see #removeSelectionListener(DataSelectionListener)
435 * @see SelectionEventManager#addSelectionListener(SelectionChangedListener,
436 * org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode)
437 * To add a global listener.
438 */
439 void addSelectionListener(DataSelectionListener listener);
440
441 /**
442 * Remove a listener that listens to selection changes in this specific data set.
443 * @param listener The listener.
444 * @see #addSelectionListener(DataSelectionListener)
445 */
446 void removeSelectionListener(DataSelectionListener listener);
447
448 // -------------------
449 // Miscellaneous
450 // -------------------
451
452 /**
453 * Returns the data sources bounding box.
454 * @return the data sources bounding box
455 */
456 default ProjectionBounds getDataSourceBoundingBox() {
457 BoundingXYVisitor bbox = new BoundingXYVisitor();
458 for (DataSource source : getDataSources()) {
459 bbox.visit(source.bounds);
460 }
461 if (bbox.hasExtend()) {
462 return bbox.getBounds();
463 }
464 return null;
465 }
466
467 /**
468 * Clear the mappaint cache for this DataSet.
469 * @since 13420
470 */
471 void clearMappaintCache();
472
473 /**
474 * Replies true if there is at least one primitive in this dataset with
475 * {@link IPrimitive#isModified()} == <code>true</code>.
476 *
477 * @return true if there is at least one primitive in this dataset with
478 * {@link IPrimitive#isModified()} == <code>true</code>.
479 */
480 default boolean isModified() {
481 return false;
482 }
483}
Note: See TracBrowser for help on using the repository browser.