001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.osm.history;
003
004import java.util.Date;
005
006import org.openstreetmap.josm.data.coor.LatLon;
007import org.openstreetmap.josm.data.osm.Node;
008import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
009import org.openstreetmap.josm.data.osm.User;
010
011/**
012 * Represents an immutable OSM node in the context of a historical view on
013 * OSM data.
014 *
015 */
016public class HistoryNode extends HistoryOsmPrimitive {
017
018    /** the coordinates. May be null for deleted nodes */
019    private LatLon coords;
020
021    /**
022     * Constructs a new {@code HistoryNode}.
023     *
024     * @param id the id (> 0 required)
025     * @param version the version (> 0 required)
026     * @param visible whether the node is still visible
027     * @param user the user (!= null required)
028     * @param changesetId the changeset id (> 0 required)
029     * @param timestamp the timestamp (!= null required)
030     * @param coords the coordinates
031     * @throws IllegalArgumentException if preconditions are violated
032     */
033    public HistoryNode(long id, long version, boolean visible, User user, long changesetId, Date timestamp, LatLon coords) throws IllegalArgumentException {
034        this(id, version, visible, user, changesetId, timestamp, coords, true);
035    }
036
037    /**
038     * Constructs a new {@code HistoryNode} with a configurable checking of historic parameters.
039     * This is needed to build virtual HistoryNodes for modified nodes, which do not have a timestamp and a changeset id.
040     *
041     * @param id the id (> 0 required)
042     * @param version the version (> 0 required)
043     * @param visible whether the node is still visible
044     * @param user the user (!= null required)
045     * @param changesetId the changeset id (> 0 required if {@code checkHistoricParams} is true)
046     * @param timestamp the timestamp (!= null required if {@code checkHistoricParams} is true)
047     * @param coords the coordinates
048     * @param checkHistoricParams if true, checks values of {@code changesetId} and {@code timestamp}
049     * @throws IllegalArgumentException if preconditions are violated
050     * @since 5440
051     */
052    public HistoryNode(long id, long version, boolean visible, User user, long changesetId, Date timestamp, LatLon coords, boolean checkHistoricParams) throws IllegalArgumentException {
053        super(id, version, visible, user, changesetId, timestamp, checkHistoricParams);
054        setCoords(coords);
055    }
056
057    /**
058     * Constructs a new {@code HistoryNode} from an existing {@link Node}.
059     * @param n the node
060     */
061    public HistoryNode(Node n) {
062        super(n);
063        setCoords(n.getCoor());
064    }
065
066    @Override
067    public OsmPrimitiveType getType() {
068        return OsmPrimitiveType.NODE;
069    }
070
071    /**
072     * Replies the coordinates. May be null.
073     * @return the coordinates. May be null.
074     */
075    public final LatLon getCoords() {
076        return coords;
077    }
078
079    /**
080     * Sets the coordinates. Can be null.
081     * @param coords the coordinates. Can be null.
082     */
083    public final void setCoords(LatLon coords) {
084        this.coords = coords;
085    }
086
087    @Override
088    public String getDisplayName(HistoryNameFormatter formatter) {
089        return formatter.format(this);
090    }
091}