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 static final UniqueIdGenerator idGenerator = Way.idGenerator; 017 private List<Long> nodes = new ArrayList<>(); 018 019 /** 020 * Constructs a new {@code NodeData}. 021 */ 022 public WayData() { 023 // contents can be set later with setters 024 this(idGenerator.generateUniqueId()); 025 } 026 027 /** 028 * Constructs a new {@code WayData} with given id. 029 * @param id id 030 * @since 12017 031 */ 032 public WayData(long id) { 033 super(id); 034 } 035 036 /** 037 * Constructs a new {@code WayData}. 038 * @param data way data to copy 039 */ 040 public WayData(WayData data) { 041 super(data); 042 nodes.addAll(data.getNodeIds()); 043 } 044 045 @Override 046 public List<NodeData> getNodes() { 047 throw new UnsupportedOperationException("Use getNodeIds() instead"); 048 } 049 050 @Override 051 public NodeData getNode(int index) { 052 throw new UnsupportedOperationException("Use getNodeId(int) instead"); 053 } 054 055 @Override 056 public List<Long> getNodeIds() { 057 return nodes; 058 } 059 060 @Override 061 public int getNodesCount() { 062 return nodes.size(); 063 } 064 065 @Override 066 public long getNodeId(int idx) { 067 return nodes.get(idx); 068 } 069 070 @Override 071 public boolean isClosed() { 072 if (isIncomplete()) return false; 073 return nodes.get(0).equals(nodes.get(nodes.size() - 1)); 074 } 075 076 @Override 077 public void setNodes(List<NodeData> nodes) { 078 throw new UnsupportedOperationException("Use setNodeIds(List) instead"); 079 } 080 081 /** 082 * Sets the nodes array 083 * @param nodes The nodes this way consists of 084 * @since 13907 085 */ 086 public void setNodeIds(List<Long> nodes) { 087 this.nodes = new ArrayList<>(nodes); 088 } 089 090 @Override 091 public WayData makeCopy() { 092 return new WayData(this); 093 } 094 095 @Override 096 public String toString() { 097 return super.toString() + " WAY" + nodes; 098 } 099 100 @Override 101 public OsmPrimitiveType getType() { 102 return OsmPrimitiveType.WAY; 103 } 104 105 @Override 106 public void accept(PrimitiveVisitor visitor) { 107 visitor.visit(this); 108 } 109 110 @Override 111 public BBox getBBox() { 112 throw new UnsupportedOperationException(); 113 } 114 115 @Override 116 public NodeData firstNode() { 117 throw new UnsupportedOperationException(); 118 } 119 120 @Override 121 public NodeData lastNode() { 122 throw new UnsupportedOperationException(); 123 } 124 125 @Override 126 public boolean isFirstLastNode(INode n) { 127 throw new UnsupportedOperationException(); 128 } 129 130 @Override 131 public boolean isInnerNode(INode n) { 132 throw new UnsupportedOperationException(); 133 } 134 135 @Override 136 public UniqueIdGenerator getIdGenerator() { 137 return idGenerator; 138 } 139}