001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.osm; 003 004/** 005 * IWay captures the common functions of {@link Way} and {@link WayData}. 006 * @since 4098 007 */ 008public interface IWay extends IPrimitive { 009 010 /** 011 * Replies the number of nodes in this way. 012 * 013 * @return the number of nodes in this way. 014 */ 015 int getNodesCount(); 016 017 /** 018 * Replies the real number of nodes in this way (full number of nodes minus one if this way is closed) 019 * 020 * @return the real number of nodes in this way. 021 * 022 * @see #getNodesCount() 023 * @see #isClosed() 024 * @since 5847 025 * @since 13564 (IWay) 026 */ 027 default int getRealNodesCount() { 028 int count = getNodesCount(); 029 return isClosed() ? count-1 : count; 030 } 031 032 /** 033 * Returns id of the node at given index. 034 * @param idx node index 035 * @return id of the node at given index 036 */ 037 long getNodeId(int idx); 038 039 /** 040 * Determines if this way is closed. 041 * @return {@code true} if this way is closed, {@code false} otherwise 042 */ 043 boolean isClosed(); 044 045 @Override 046 default int compareTo(IPrimitive o) { 047 if (o instanceof IRelation) 048 return 1; 049 return o instanceof IWay ? Long.compare(getUniqueId(), o.getUniqueId()) : -1; 050 } 051 052 @Override 053 default String getDisplayName(NameFormatter formatter) { 054 return formatter.format(this); 055 } 056}