001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.osm;
003
004import org.openstreetmap.josm.Main;
005import org.openstreetmap.josm.data.coor.EastNorth;
006import org.openstreetmap.josm.data.coor.ILatLon;
007import org.openstreetmap.josm.data.coor.LatLon;
008
009/**
010 * INode captures the common functions of {@link Node} and {@link NodeData}.
011 * @since 4098
012 */
013public interface INode extends IPrimitive, ILatLon {
014
015    /**
016     * Returns lat/lon coordinates of this node.
017     * @return lat/lon coordinates of this node
018     */
019    LatLon getCoor();
020
021    /**
022     * Sets lat/lon coordinates of this node.
023     * @param coor lat/lon coordinates of this node
024     */
025    void setCoor(LatLon coor);
026
027    /**
028     * Replies the projected east/north coordinates.
029     * <p>
030     * Uses the {@link Main#getProjection() global projection} to project the lat/lon-coordinates.
031     * <p>
032     * @return the east north coordinates or {@code null} if {@link #isLatLonKnown()} is false.
033     * @since 13666
034     */
035    default EastNorth getEastNorth() {
036        return getEastNorth(Main.getProjection());
037    }
038
039    /**
040     * Sets east/north coordinates of this node.
041     * @param eastNorth east/north coordinates of this node
042     */
043    void setEastNorth(EastNorth eastNorth);
044
045    /**
046     * Check whether this node connects 2 ways.
047     *
048     * @return true if isReferredByWays(2) returns true
049     * @see #isReferredByWays(int)
050     * @since 13669
051     */
052    default boolean isConnectionNode() {
053        return isReferredByWays(2);
054    }
055
056    /**
057     * Return true, if this primitive is referred by at least n ways
058     * @param n Minimal number of ways to return true. Must be positive
059     * @return {@code true} if this primitive is referred by at least n ways
060     * @since 13669
061     */
062    boolean isReferredByWays(int n);
063
064    @Override
065    default int compareTo(IPrimitive o) {
066        return o instanceof INode ? Long.compare(getUniqueId(), o.getUniqueId()) : 1;
067    }
068
069    @Override
070    default String getDisplayName(NameFormatter formatter) {
071        return formatter.format(this);
072    }
073}