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

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

API alignment between Relation/RelationData and RelationMember/RelationMemberData: update of IRelation/IRelationMember interfaces

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import 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 */
11public 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> &lt; 0
41 * or <code>index</code> &gt;= {@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 * Determines if this way is closed.
71 * @return {@code true} if this way is closed, {@code false} otherwise
72 */
73 boolean isClosed();
74
75 @Override
76 default int compareTo(IPrimitive o) {
77 if (o instanceof IRelation)
78 return 1;
79 return o instanceof IWay ? Long.compare(getUniqueId(), o.getUniqueId()) : -1;
80 }
81
82 @Override
83 default String getDisplayName(NameFormatter formatter) {
84 return formatter.format(this);
85 }
86}
Note: See TracBrowser for help on using the repository browser.