source: josm/trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java@ 13916

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

move hasSameInterestingTags() implementation from AbstractPrimitive to IPrimitive

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