1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * IWay captures the common functions of {@link Way} and {@link WayData}.
|
---|
8 | * @param <N> type of OSM node
|
---|
9 | * @since 4098
|
---|
10 | */
|
---|
11 | public interface IWay<N extends INode> extends IPrimitive {
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Replies the number of nodes in this way.
|
---|
15 | *
|
---|
16 | * @return the number of nodes in this way.
|
---|
17 | */
|
---|
18 | int getNodesCount();
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Replies the real number of nodes in this way (full number of nodes minus one if this way is closed)
|
---|
22 | *
|
---|
23 | * @return the real number of nodes in this way.
|
---|
24 | *
|
---|
25 | * @see #getNodesCount()
|
---|
26 | * @see #isClosed()
|
---|
27 | * @since 5847
|
---|
28 | * @since 13564 (IWay)
|
---|
29 | */
|
---|
30 | default int getRealNodesCount() {
|
---|
31 | int count = getNodesCount();
|
---|
32 | return isClosed() ? count-1 : count;
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Replies the node at position <code>index</code>.
|
---|
37 | *
|
---|
38 | * @param index the position
|
---|
39 | * @return the node at position <code>index</code>
|
---|
40 | * @throws ArrayIndexOutOfBoundsException if <code>index</code> < 0
|
---|
41 | * or <code>index</code> >= {@link #getNodesCount()}
|
---|
42 | * @since 1862
|
---|
43 | * @since 13717 (IWay)
|
---|
44 | */
|
---|
45 | N getNode(int index);
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Returns the list of nodes in this way.
|
---|
49 | * @return the list of nodes in this way
|
---|
50 | * @since 1862
|
---|
51 | * @since 13717 (IWay)
|
---|
52 | */
|
---|
53 | List<N> getNodes();
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Returns the list of node ids in this way.
|
---|
57 | * @return the list of node ids in this way
|
---|
58 | * @since 13717
|
---|
59 | */
|
---|
60 | List<Long> getNodeIds();
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Returns id of the node at given index.
|
---|
64 | * @param idx node index
|
---|
65 | * @return id of the node at given index
|
---|
66 | */
|
---|
67 | long getNodeId(int idx);
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Set new list of nodes to way. This method is preferred to multiple calls to addNode/removeNode
|
---|
71 | * and similar methods because nodes are internally saved as array which means lower memory overhead
|
---|
72 | * but also slower modifying operations.
|
---|
73 | * @param nodes New way nodes. Can be null, in that case all way nodes are removed
|
---|
74 | */
|
---|
75 | void setNodes(List<N> nodes);
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Determines if this way is closed.
|
---|
79 | * @return {@code true} if this way is closed, {@code false} otherwise
|
---|
80 | */
|
---|
81 | boolean isClosed();
|
---|
82 |
|
---|
83 | @Override
|
---|
84 | default int compareTo(IPrimitive o) {
|
---|
85 | if (o instanceof IRelation)
|
---|
86 | return 1;
|
---|
87 | return o instanceof IWay ? Long.compare(getUniqueId(), o.getUniqueId()) : -1;
|
---|
88 | }
|
---|
89 |
|
---|
90 | @Override
|
---|
91 | default String getDisplayName(NameFormatter formatter) {
|
---|
92 | return formatter.format(this);
|
---|
93 | }
|
---|
94 | }
|
---|