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

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

define InterestingTags functions in IPrimitive

  • Property svn:eol-style set to native
File size: 13.9 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 PrimitiveId getPrimitiveId();
206
207 /**
208 * Replies the version number as returned by the API. The version is 0 if the id is 0 or
209 * if this primitive is incomplete.
210 * @return the version number as returned by the API
211 *
212 * @see PrimitiveData#setVersion(int)
213 */
214 int getVersion();
215
216 /**
217 * Sets the id and the version of this primitive if it is known to the OSM API.
218 *
219 * Since we know the id and its version it can't be incomplete anymore. incomplete
220 * is set to false.
221 *
222 * @param id the id. &gt; 0 required
223 * @param version the version &gt; 0 required
224 * @throws IllegalArgumentException if id &lt;= 0
225 * @throws IllegalArgumentException if version &lt;= 0
226 * @throws DataIntegrityProblemException if id is changed and primitive was already added to the dataset
227 */
228 void setOsmId(long id, int version);
229
230 /**
231 * Replies the user who has last touched this object. May be null.
232 *
233 * @return the user who has last touched this object. May be null.
234 */
235 User getUser();
236
237 /**
238 * Sets the user who has last touched this object.
239 *
240 * @param user the user
241 */
242 void setUser(User user);
243
244 /**
245 * Time of last modification to this object. This is not set by JOSM but
246 * read from the server and delivered back to the server unmodified. It is
247 * used to check against edit conflicts.
248 *
249 * @return date of last modification
250 * @see #setTimestamp
251 */
252 Date getTimestamp();
253
254 /**
255 * Time of last modification to this object. This is not set by JOSM but
256 * read from the server and delivered back to the server unmodified. It is
257 * used to check against edit conflicts.
258 *
259 * @return last modification as timestamp
260 * @see #setRawTimestamp
261 */
262 int getRawTimestamp();
263
264 /**
265 * Sets time of last modification to this object
266 * @param timestamp date of last modification
267 * @see #getTimestamp
268 */
269 void setTimestamp(Date timestamp);
270
271 /**
272 * Sets time of last modification to this object
273 * @param timestamp date of last modification
274 * @see #getRawTimestamp
275 */
276 void setRawTimestamp(int timestamp);
277
278 /**
279 * Determines if this primitive has no timestamp information.
280 * @return {@code true} if this primitive has no timestamp information
281 * @see #getTimestamp
282 * @see #getRawTimestamp
283 */
284 boolean isTimestampEmpty();
285
286 /**
287 * Replies the id of the changeset this primitive was last uploaded to.
288 * 0 if this primitive wasn't uploaded to a changeset yet or if the
289 * changeset isn't known.
290 *
291 * @return the id of the changeset this primitive was last uploaded to.
292 */
293 int getChangesetId();
294
295 /**
296 * Sets the changeset id of this primitive. Can't be set on a new primitive.
297 *
298 * @param changesetId the id. &gt;= 0 required.
299 * @throws IllegalStateException if this primitive is new.
300 * @throws IllegalArgumentException if id &lt; 0
301 */
302 void setChangesetId(int changesetId);
303
304 /**
305 * Makes the given visitor visit this primitive.
306 * @param visitor visitor
307 */
308 void accept(PrimitiveVisitor visitor);
309
310 /**
311 * <p>Visits {@code visitor} for all referrers.</p>
312 *
313 * @param visitor the visitor. Ignored, if null.
314 * @since 13806
315 */
316 void visitReferrers(PrimitiveVisitor visitor);
317
318 /**
319 * Replies the name of this primitive. The default implementation replies the value
320 * of the tag <code>name</code> or null, if this tag is not present.
321 *
322 * @return the name of this primitive
323 */
324 String getName();
325
326 /**
327 * Replies a localized name for this primitive given by the value of the name tags
328 * accessed from very specific (language variant) to more generic (default name).
329 *
330 * @return the name of this primitive, <code>null</code> if no name exists
331 * @see LanguageInfo#getLanguageCodes
332 */
333 String getLocalName();
334
335 /**
336 * Replies the display name of a primitive formatted by <code>formatter</code>
337 * @param formatter formatter to use
338 *
339 * @return the display name
340 * @since 13564
341 */
342 String getDisplayName(NameFormatter formatter);
343
344 /**
345 * Gets the type this primitive is displayed at
346 * @return A {@link OsmPrimitiveType}
347 * @since 13564
348 */
349 default OsmPrimitiveType getDisplayType() {
350 return getType();
351 }
352
353 /**
354 * Updates the highlight flag for this primitive.
355 * @param highlighted The new highlight flag.
356 * @since 13664
357 */
358 void setHighlighted(boolean highlighted);
359
360 /**
361 * Checks if the highlight flag for this primitive was set
362 * @return The highlight flag.
363 * @since 13664
364 */
365 boolean isHighlighted();
366
367 /**
368 * Determines if this object is considered "tagged". To be "tagged", an object
369 * must have one or more "interesting" tags. "created_by" and "source"
370 * are typically considered "uninteresting" and do not make an object "tagged".
371 * @return true if this object is considered "tagged"
372 * @since 13662
373 */
374 boolean isTagged();
375
376 /**
377 * Determines if this object is considered "annotated". To be "annotated", an object
378 * must have one or more "work in progress" tags, such as "note" or "fixme".
379 * @return true if this object is considered "annotated"
380 * @since 13662
381 */
382 boolean isAnnotated();
383
384 /**
385 * Determines if this object is a relation and behaves as a multipolygon.
386 * @return {@code true} if it is a real multipolygon or a boundary relation
387 * @since 13667
388 */
389 default boolean isMultipolygon() {
390 return false;
391 }
392
393 /**
394 * true if this object has direction dependent tags (e.g. oneway)
395 * @return {@code true} if this object has direction dependent tags
396 * @since 13662
397 */
398 boolean hasDirectionKeys();
399
400 /**
401 * true if this object has the "reversed direction" flag enabled
402 * @return {@code true} if this object has the "reversed direction" flag enabled
403 * @since 13662
404 */
405 boolean reversedDirection();
406
407 /**
408 * Fetches the bounding box of the primitive.
409 * @return Bounding box of the object
410 * @since 13764
411 */
412 BBox getBBox();
413
414 /**
415 * Gets a list of all primitives in the current dataset that reference this primitive.
416 * @return The referrers
417 * @since 13764
418 */
419 default List<? extends IPrimitive> getReferrers() {
420 return getReferrers(false);
421 }
422
423 /**
424 * Find primitives that reference this primitive. Returns only primitives that are included in the same
425 * dataset as this primitive. <br>
426 *
427 * For example following code will add wnew as referer to all nodes of existingWay, but this method will
428 * not return wnew because it's not part of the dataset <br>
429 *
430 * <code>Way wnew = new Way(existingWay)</code>
431 *
432 * @param allowWithoutDataset If true, method will return empty list if primitive is not part of the dataset. If false,
433 * exception will be thrown in this case
434 *
435 * @return a collection of all primitives that reference this primitive.
436 * @since 13808
437 */
438 List<? extends IPrimitive> getReferrers(boolean allowWithoutDataset);
439
440 /**
441 * Returns the parent data set of this primitive.
442 * @return OsmData this primitive is part of.
443 * @since 13807
444 */
445 OsmData<?, ?, ?, ?> getDataSet();
446
447 /**
448 * Returns {@link #getKeys()} for which {@code key} does not fulfill uninteresting criteria.
449 * @return A map of interesting tags
450 * @since 13809
451 */
452 Map<String, String> getInterestingTags();
453
454 /**
455 * Replies true if other isn't null and has the same interesting tags (key/value-pairs) as this.
456 *
457 * @param other the other object primitive
458 * @return true if other isn't null and has the same interesting tags (key/value-pairs) as this.
459 * @since 13809
460 */
461 boolean hasSameInterestingTags(IPrimitive other);
462}
Note: See TracBrowser for help on using the repository browser.