001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.osm;
003
004import java.util.ArrayList;
005import java.util.List;
006
007import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
008
009/**
010 * The data (tags and node ids) that is stored for a way in the database.
011 * @since 2284
012 */
013public class WayData extends PrimitiveData implements IWay<NodeData> {
014
015    private static final long serialVersionUID = 106944939313286415L;
016    private List<Long> nodes = new ArrayList<>();
017
018    /**
019     * Constructs a new {@code NodeData}.
020     */
021    public WayData() {
022        // contents can be set later with setters
023    }
024
025    /**
026     * Constructs a new {@code WayData} with given id.
027     * @param id id
028     * @since 12017
029     */
030    public WayData(long id) {
031        super(id);
032    }
033
034    /**
035     * Constructs a new {@code WayData}.
036     * @param data way data to copy
037     */
038    public WayData(WayData data) {
039        super(data);
040        nodes.addAll(data.getNodeIds());
041    }
042
043    @Override
044    public List<NodeData> getNodes() {
045        throw new UnsupportedOperationException("Use getNodeIds() instead");
046    }
047
048    @Override
049    public NodeData getNode(int index) {
050        throw new UnsupportedOperationException("Use getNodeId(int) instead");
051    }
052
053    @Override
054    public List<Long> getNodeIds() {
055        return nodes;
056    }
057
058    @Override
059    public int getNodesCount() {
060        return nodes.size();
061    }
062
063    @Override
064    public long getNodeId(int idx) {
065        return nodes.get(idx);
066    }
067
068    @Override
069    public boolean isClosed() {
070        if (isIncomplete()) return false;
071        return nodes.get(0).equals(nodes.get(nodes.size() - 1));
072    }
073
074    @Override
075    public void setNodes(List<NodeData> nodes) {
076        throw new UnsupportedOperationException("Use setNodeIds(List) instead");
077    }
078
079    /**
080     * Sets the nodes array
081     * @param nodes The nodes this way consists of
082     * @since 13907
083     */
084    public void setNodeIds(List<Long> nodes) {
085        this.nodes = new ArrayList<>(nodes);
086    }
087
088    @Override
089    public WayData makeCopy() {
090        return new WayData(this);
091    }
092
093    @Override
094    public String toString() {
095        return super.toString() + " WAY" + nodes;
096    }
097
098    @Override
099    public OsmPrimitiveType getType() {
100        return OsmPrimitiveType.WAY;
101    }
102
103    @Override
104    public void accept(PrimitiveVisitor visitor) {
105        visitor.visit(this);
106    }
107
108    @Override
109    public BBox getBBox() {
110        throw new UnsupportedOperationException();
111    }
112
113    @Override
114    public NodeData firstNode() {
115        throw new UnsupportedOperationException();
116    }
117
118    @Override
119    public NodeData lastNode() {
120        throw new UnsupportedOperationException();
121    }
122
123    @Override
124    public boolean isFirstLastNode(INode n) {
125        throw new UnsupportedOperationException();
126    }
127
128    @Override
129    public boolean isInnerNode(INode n) {
130        throw new UnsupportedOperationException();
131    }
132}