1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * IRelation captures the common functions of {@link Relation} and {@link RelationData}.
|
---|
8 | * @param <M> Type of OSM relation member
|
---|
9 | * @since 4098
|
---|
10 | */
|
---|
11 | public interface IRelation<M extends IRelationMember<?>> extends IPrimitive {
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Returns the number of members.
|
---|
15 | * @return number of members
|
---|
16 | */
|
---|
17 | int getMembersCount();
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Returns the relation member at the specified index.
|
---|
21 | * @param index the index of the relation member
|
---|
22 | * @return relation member at the specified index
|
---|
23 | * @since 13766 (IRelation)
|
---|
24 | */
|
---|
25 | M getMember(int index);
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Returns members of the relation.
|
---|
29 | * @return Members of the relation. Changes made in returned list are not mapped
|
---|
30 | * back to the primitive, use setMembers() to modify the members
|
---|
31 | * @since 1925
|
---|
32 | * @since 13766 (IRelation)
|
---|
33 | */
|
---|
34 | List<M> getMembers();
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Returns id of the member at given index.
|
---|
38 | * @param idx member index
|
---|
39 | * @return id of the member at given index
|
---|
40 | */
|
---|
41 | long getMemberId(int idx);
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Returns role of the member at given index.
|
---|
45 | * @param idx member index
|
---|
46 | * @return role of the member at given index
|
---|
47 | */
|
---|
48 | String getRole(int idx);
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Returns type of the member at given index.
|
---|
52 | * @param idx member index
|
---|
53 | * @return type of the member at given index
|
---|
54 | */
|
---|
55 | OsmPrimitiveType getMemberType(int idx);
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Determines if at least one child primitive is incomplete.
|
---|
59 | *
|
---|
60 | * @return true if at least one child primitive is incomplete
|
---|
61 | * @since 13564
|
---|
62 | */
|
---|
63 | default boolean hasIncompleteMembers() {
|
---|
64 | return false;
|
---|
65 | }
|
---|
66 |
|
---|
67 | @Override
|
---|
68 | default int compareTo(IPrimitive o) {
|
---|
69 | return o instanceof IRelation ? Long.compare(getUniqueId(), o.getUniqueId()) : -1;
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Override
|
---|
73 | default String getDisplayName(NameFormatter formatter) {
|
---|
74 | return formatter.format(this);
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Determines if this relation is a boundary.
|
---|
79 | * @return {@code true} if a boundary relation
|
---|
80 | */
|
---|
81 | default boolean isBoundary() {
|
---|
82 | return "boundary".equals(get("type"));
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override
|
---|
86 | default boolean isMultipolygon() {
|
---|
87 | return "multipolygon".equals(get("type")) || isBoundary();
|
---|
88 | }
|
---|
89 | }
|
---|