1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.util.Date;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
|
---|
8 | import org.openstreetmap.josm.tools.LanguageInfo;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * IPrimitive captures the common functions of {@link OsmPrimitive} and {@link PrimitiveData}.
|
---|
12 | * @since 4098
|
---|
13 | */
|
---|
14 | public interface IPrimitive extends Tagged, PrimitiveId, Stylable, Comparable<IPrimitive> {
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Replies <code>true</code> if the object has been modified since it was loaded from
|
---|
18 | * the server. In this case, on next upload, this object will be updated.
|
---|
19 | *
|
---|
20 | * Deleted objects are deleted from the server. If the objects are added (id=0),
|
---|
21 | * the modified is ignored and the object is added to the server.
|
---|
22 | *
|
---|
23 | * @return <code>true</code> if the object has been modified since it was loaded from
|
---|
24 | * the server
|
---|
25 | */
|
---|
26 | boolean isModified();
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Marks this primitive as being modified.
|
---|
30 | *
|
---|
31 | * @param modified true, if this primitive is to be modified
|
---|
32 | */
|
---|
33 | void setModified(boolean modified);
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Checks if object is known to the server.
|
---|
37 | * Replies true if this primitive is either unknown to the server (i.e. its id
|
---|
38 | * is 0) or it is known to the server and it hasn't be deleted on the server.
|
---|
39 | * Replies false, if this primitive is known on the server and has been deleted
|
---|
40 | * on the server.
|
---|
41 | *
|
---|
42 | * @return <code>true</code>, if the object is visible on server.
|
---|
43 | * @see #setVisible(boolean)
|
---|
44 | */
|
---|
45 | boolean isVisible();
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Sets whether this primitive is visible, i.e. whether it is known on the server
|
---|
49 | * and not deleted on the server.
|
---|
50 | * @param visible {@code true} if this primitive is visible
|
---|
51 | *
|
---|
52 | * @throws IllegalStateException if visible is set to false on an primitive with id==0
|
---|
53 | * @see #isVisible()
|
---|
54 | */
|
---|
55 | void setVisible(boolean visible);
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Replies <code>true</code>, if the object has been deleted.
|
---|
59 | *
|
---|
60 | * @return <code>true</code>, if the object has been deleted.
|
---|
61 | * @see #setDeleted(boolean)
|
---|
62 | */
|
---|
63 | boolean isDeleted();
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Sets whether this primitive is deleted or not.
|
---|
67 | *
|
---|
68 | * Also marks this primitive as modified if deleted is true.
|
---|
69 | *
|
---|
70 | * @param deleted true, if this primitive is deleted; false, otherwise
|
---|
71 | */
|
---|
72 | void setDeleted(boolean deleted);
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * Determines if this primitive is incomplete.
|
---|
76 | * @return {@code true} if this primitive is incomplete, {@code false} otherwise
|
---|
77 | */
|
---|
78 | boolean isIncomplete();
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Replies <code>true</code> if the object has been deleted on the server and was undeleted by the user.
|
---|
82 | * @return <code>true</code> if the object has been undeleted
|
---|
83 | */
|
---|
84 | boolean isUndeleted();
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Replies <code>true</code>, if the object is usable
|
---|
88 | * (i.e. complete and not deleted).
|
---|
89 | *
|
---|
90 | * @return <code>true</code>, if the object is usable.
|
---|
91 | * @see #setDeleted(boolean)
|
---|
92 | */
|
---|
93 | boolean isUsable();
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Determines if this primitive is new or undeleted.
|
---|
97 | * @return True if primitive is new or undeleted
|
---|
98 | * @see #isNew()
|
---|
99 | * @see #isUndeleted()
|
---|
100 | */
|
---|
101 | boolean isNewOrUndeleted();
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Replies true, if this primitive is disabled. (E.g. a filter applies)
|
---|
105 | * @return {@code true} if this object has the "disabled" flag enabled
|
---|
106 | * @since 13662
|
---|
107 | */
|
---|
108 | default boolean isDisabled() {
|
---|
109 | return false;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Replies true, if this primitive is disabled and marked as completely hidden on the map.
|
---|
114 | * @return {@code true} if this object has both the "disabled" and "hide if disabled" flags enabled
|
---|
115 | * @since 13662
|
---|
116 | */
|
---|
117 | default boolean isDisabledAndHidden() {
|
---|
118 | return false;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Replies true, if this primitive is preserved from filtering.
|
---|
123 | * @return {@code true} if this object has the "preserved" flag enabled
|
---|
124 | * @since 13764
|
---|
125 | */
|
---|
126 | default boolean isPreserved() {
|
---|
127 | return false;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Determines if this object is selectable.
|
---|
132 | * <p>
|
---|
133 | * A primitive can be selected if all conditions are met:
|
---|
134 | * <ul>
|
---|
135 | * <li>it is drawable
|
---|
136 | * <li>it is not disabled (greyed out) by a filter.
|
---|
137 | * </ul>
|
---|
138 | * @return {@code true} if this object is selectable
|
---|
139 | * @since 13664
|
---|
140 | */
|
---|
141 | default boolean isSelectable() {
|
---|
142 | return true;
|
---|
143 | }
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Determines if this object is drawable.
|
---|
147 | * <p>
|
---|
148 | * A primitive is complete if all conditions are met:
|
---|
149 | * <ul>
|
---|
150 | * <li>type and id is known
|
---|
151 | * <li>tags are known
|
---|
152 | * <li>it is not deleted
|
---|
153 | * <li>it is not hidden by a filter
|
---|
154 | * <li>for nodes: lat/lon are known
|
---|
155 | * <li>for ways: all nodes are known and complete
|
---|
156 | * <li>for relations: all members are known and complete
|
---|
157 | * </ul>
|
---|
158 | * @return {@code true} if this object is drawable
|
---|
159 | * @since 13664
|
---|
160 | */
|
---|
161 | default boolean isDrawable() {
|
---|
162 | return true;
|
---|
163 | }
|
---|
164 |
|
---|
165 | /**
|
---|
166 | * Determines whether the primitive is selected
|
---|
167 | * @return whether the primitive is selected
|
---|
168 | * @since 13664
|
---|
169 | */
|
---|
170 | default boolean isSelected() {
|
---|
171 | return false;
|
---|
172 | }
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Determines if this primitive is a member of a selected relation.
|
---|
176 | * @return {@code true} if this primitive is a member of a selected relation, {@code false} otherwise
|
---|
177 | * @since 13664
|
---|
178 | */
|
---|
179 | default boolean isMemberOfSelected() {
|
---|
180 | return false;
|
---|
181 | }
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * Determines if this primitive is an outer member of a selected multipolygon relation.
|
---|
185 | * @return {@code true} if this primitive is an outer member of a selected multipolygon relation, {@code false} otherwise
|
---|
186 | * @since 13664
|
---|
187 | */
|
---|
188 | default boolean isOuterMemberOfSelected() {
|
---|
189 | return false;
|
---|
190 | }
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * Replies the id of this primitive.
|
---|
194 | *
|
---|
195 | * @return the id of this primitive.
|
---|
196 | */
|
---|
197 | long getId();
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * Replies the unique primitive id for this primitive
|
---|
201 | *
|
---|
202 | * @return the unique primitive id for this primitive
|
---|
203 | */
|
---|
204 | PrimitiveId getPrimitiveId();
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Replies the version number as returned by the API. The version is 0 if the id is 0 or
|
---|
208 | * if this primitive is incomplete.
|
---|
209 | * @return the version number as returned by the API
|
---|
210 | *
|
---|
211 | * @see PrimitiveData#setVersion(int)
|
---|
212 | */
|
---|
213 | int getVersion();
|
---|
214 |
|
---|
215 | /**
|
---|
216 | * Sets the id and the version of this primitive if it is known to the OSM API.
|
---|
217 | *
|
---|
218 | * Since we know the id and its version it can't be incomplete anymore. incomplete
|
---|
219 | * is set to false.
|
---|
220 | *
|
---|
221 | * @param id the id. > 0 required
|
---|
222 | * @param version the version > 0 required
|
---|
223 | * @throws IllegalArgumentException if id <= 0
|
---|
224 | * @throws IllegalArgumentException if version <= 0
|
---|
225 | * @throws DataIntegrityProblemException if id is changed and primitive was already added to the dataset
|
---|
226 | */
|
---|
227 | void setOsmId(long id, int version);
|
---|
228 |
|
---|
229 | /**
|
---|
230 | * Replies the user who has last touched this object. May be null.
|
---|
231 | *
|
---|
232 | * @return the user who has last touched this object. May be null.
|
---|
233 | */
|
---|
234 | User getUser();
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Sets the user who has last touched this object.
|
---|
238 | *
|
---|
239 | * @param user the user
|
---|
240 | */
|
---|
241 | void setUser(User user);
|
---|
242 |
|
---|
243 | /**
|
---|
244 | * Time of last modification to this object. This is not set by JOSM but
|
---|
245 | * read from the server and delivered back to the server unmodified. It is
|
---|
246 | * used to check against edit conflicts.
|
---|
247 | *
|
---|
248 | * @return date of last modification
|
---|
249 | * @see #setTimestamp
|
---|
250 | */
|
---|
251 | Date getTimestamp();
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * Time of last modification to this object. This is not set by JOSM but
|
---|
255 | * read from the server and delivered back to the server unmodified. It is
|
---|
256 | * used to check against edit conflicts.
|
---|
257 | *
|
---|
258 | * @return last modification as timestamp
|
---|
259 | * @see #setRawTimestamp
|
---|
260 | */
|
---|
261 | int getRawTimestamp();
|
---|
262 |
|
---|
263 | /**
|
---|
264 | * Sets time of last modification to this object
|
---|
265 | * @param timestamp date of last modification
|
---|
266 | * @see #getTimestamp
|
---|
267 | */
|
---|
268 | void setTimestamp(Date timestamp);
|
---|
269 |
|
---|
270 | /**
|
---|
271 | * Sets time of last modification to this object
|
---|
272 | * @param timestamp date of last modification
|
---|
273 | * @see #getRawTimestamp
|
---|
274 | */
|
---|
275 | void setRawTimestamp(int timestamp);
|
---|
276 |
|
---|
277 | /**
|
---|
278 | * Determines if this primitive has no timestamp information.
|
---|
279 | * @return {@code true} if this primitive has no timestamp information
|
---|
280 | * @see #getTimestamp
|
---|
281 | * @see #getRawTimestamp
|
---|
282 | */
|
---|
283 | boolean isTimestampEmpty();
|
---|
284 |
|
---|
285 | /**
|
---|
286 | * Replies the id of the changeset this primitive was last uploaded to.
|
---|
287 | * 0 if this primitive wasn't uploaded to a changeset yet or if the
|
---|
288 | * changeset isn't known.
|
---|
289 | *
|
---|
290 | * @return the id of the changeset this primitive was last uploaded to.
|
---|
291 | */
|
---|
292 | int getChangesetId();
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * Sets the changeset id of this primitive. Can't be set on a new primitive.
|
---|
296 | *
|
---|
297 | * @param changesetId the id. >= 0 required.
|
---|
298 | * @throws IllegalStateException if this primitive is new.
|
---|
299 | * @throws IllegalArgumentException if id < 0
|
---|
300 | */
|
---|
301 | void setChangesetId(int changesetId);
|
---|
302 |
|
---|
303 | /**
|
---|
304 | * Makes the given visitor visit this primitive.
|
---|
305 | * @param visitor visitor
|
---|
306 | */
|
---|
307 | void accept(PrimitiveVisitor visitor);
|
---|
308 |
|
---|
309 | /**
|
---|
310 | * <p>Visits {@code visitor} for all referrers.</p>
|
---|
311 | *
|
---|
312 | * @param visitor the visitor. Ignored, if null.
|
---|
313 | * @since 13806
|
---|
314 | */
|
---|
315 | void visitReferrers(PrimitiveVisitor visitor);
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Replies the name of this primitive. The default implementation replies the value
|
---|
319 | * of the tag <code>name</code> or null, if this tag is not present.
|
---|
320 | *
|
---|
321 | * @return the name of this primitive
|
---|
322 | */
|
---|
323 | String getName();
|
---|
324 |
|
---|
325 | /**
|
---|
326 | * Replies a localized name for this primitive given by the value of the name tags
|
---|
327 | * accessed from very specific (language variant) to more generic (default name).
|
---|
328 | *
|
---|
329 | * @return the name of this primitive, <code>null</code> if no name exists
|
---|
330 | * @see LanguageInfo#getLanguageCodes
|
---|
331 | */
|
---|
332 | String getLocalName();
|
---|
333 |
|
---|
334 | /**
|
---|
335 | * Replies the display name of a primitive formatted by <code>formatter</code>
|
---|
336 | * @param formatter formatter to use
|
---|
337 | *
|
---|
338 | * @return the display name
|
---|
339 | * @since 13564
|
---|
340 | */
|
---|
341 | String getDisplayName(NameFormatter formatter);
|
---|
342 |
|
---|
343 | /**
|
---|
344 | * Gets the type this primitive is displayed at
|
---|
345 | * @return A {@link OsmPrimitiveType}
|
---|
346 | * @since 13564
|
---|
347 | */
|
---|
348 | default OsmPrimitiveType getDisplayType() {
|
---|
349 | return getType();
|
---|
350 | }
|
---|
351 |
|
---|
352 | /**
|
---|
353 | * Updates the highlight flag for this primitive.
|
---|
354 | * @param highlighted The new highlight flag.
|
---|
355 | * @since 13664
|
---|
356 | */
|
---|
357 | void setHighlighted(boolean highlighted);
|
---|
358 |
|
---|
359 | /**
|
---|
360 | * Checks if the highlight flag for this primitive was set
|
---|
361 | * @return The highlight flag.
|
---|
362 | * @since 13664
|
---|
363 | */
|
---|
364 | boolean isHighlighted();
|
---|
365 |
|
---|
366 | /**
|
---|
367 | * Determines if this object is considered "tagged". To be "tagged", an object
|
---|
368 | * must have one or more "interesting" tags. "created_by" and "source"
|
---|
369 | * are typically considered "uninteresting" and do not make an object "tagged".
|
---|
370 | * @return true if this object is considered "tagged"
|
---|
371 | * @since 13662
|
---|
372 | */
|
---|
373 | boolean isTagged();
|
---|
374 |
|
---|
375 | /**
|
---|
376 | * Determines if this object is considered "annotated". To be "annotated", an object
|
---|
377 | * must have one or more "work in progress" tags, such as "note" or "fixme".
|
---|
378 | * @return true if this object is considered "annotated"
|
---|
379 | * @since 13662
|
---|
380 | */
|
---|
381 | boolean isAnnotated();
|
---|
382 |
|
---|
383 | /**
|
---|
384 | * Determines if this object is a relation and behaves as a multipolygon.
|
---|
385 | * @return {@code true} if it is a real multipolygon or a boundary relation
|
---|
386 | * @since 13667
|
---|
387 | */
|
---|
388 | default boolean isMultipolygon() {
|
---|
389 | return false;
|
---|
390 | }
|
---|
391 |
|
---|
392 | /**
|
---|
393 | * true if this object has direction dependent tags (e.g. oneway)
|
---|
394 | * @return {@code true} if this object has direction dependent tags
|
---|
395 | * @since 13662
|
---|
396 | */
|
---|
397 | boolean hasDirectionKeys();
|
---|
398 |
|
---|
399 | /**
|
---|
400 | * true if this object has the "reversed direction" flag enabled
|
---|
401 | * @return {@code true} if this object has the "reversed direction" flag enabled
|
---|
402 | * @since 13662
|
---|
403 | */
|
---|
404 | boolean reversedDirection();
|
---|
405 |
|
---|
406 | /**
|
---|
407 | * Fetches the bounding box of the primitive.
|
---|
408 | * @return Bounding box of the object
|
---|
409 | * @since 13764
|
---|
410 | */
|
---|
411 | BBox getBBox();
|
---|
412 |
|
---|
413 | /**
|
---|
414 | * Gets a list of all primitives in the current dataset that reference this primitive.
|
---|
415 | * @return The referrers
|
---|
416 | * @since 13764
|
---|
417 | */
|
---|
418 | List<? extends IPrimitive> getReferrers();
|
---|
419 | }
|
---|