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 */ 012public class WayData extends PrimitiveData implements IWay { 013 014 private static final long serialVersionUID = 106944939313286415L; 015 private List<Long> nodes = new ArrayList<>(); 016 017 /** 018 * Constructs a new {@code NodeData}. 019 */ 020 public WayData() { 021 // contents can be set later with setters 022 } 023 024 /** 025 * Constructs a new {@code WayData} with given id. 026 * @param id id 027 * @since 12017 028 */ 029 public WayData(long id) { 030 super(id); 031 } 032 033 /** 034 * Constructs a new {@code WayData}. 035 * @param data way data to copy 036 */ 037 public WayData(WayData data) { 038 super(data); 039 nodes.addAll(data.getNodes()); 040 } 041 042 /** 043 * Gets a list of nodes the way consists of 044 * @return The ids of the nodes 045 */ 046 public List<Long> getNodes() { 047 return nodes; 048 } 049 050 @Override 051 public int getNodesCount() { 052 return nodes.size(); 053 } 054 055 @Override 056 public long getNodeId(int idx) { 057 return nodes.get(idx); 058 } 059 060 @Override 061 public boolean isClosed() { 062 if (isIncomplete()) return false; 063 return nodes.get(0).equals(nodes.get(nodes.size() - 1)); 064 } 065 066 /** 067 * Sets the nodes array 068 * @param nodes The nodes this way consists of 069 */ 070 public void setNodes(List<Long> nodes) { 071 this.nodes = new ArrayList<>(nodes); 072 } 073 074 @Override 075 public WayData makeCopy() { 076 return new WayData(this); 077 } 078 079 @Override 080 public String toString() { 081 return super.toString() + " WAY" + nodes; 082 } 083 084 @Override 085 public OsmPrimitiveType getType() { 086 return OsmPrimitiveType.WAY; 087 } 088 089 @Override 090 public void accept(PrimitiveVisitor visitor) { 091 visitor.visit(this); 092 } 093 094}