source: josm/trunk/src/org/openstreetmap/josm/data/osm/WayData.java@ 12190

Last change on this file since 12190 was 12190, checked in by michael2402, 7 years ago

See #14794: More javadoc for data.osm package

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import java.util.ArrayList;
5import java.util.Collections;
6import java.util.List;
7
8import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
9
10/**
11 * The data (tags and node ids) that is stored for a way in the database
12 */
13public class WayData extends PrimitiveData implements IWay {
14
15 private static final long serialVersionUID = 106944939313286415L;
16 private List<Long> nodes = new ArrayList<>();
17
18 /**
19 * Constructs a new {@code NodeData}.
20 */
21 public WayData() {
22 // contents can be set later with setters
23 }
24
25 /**
26 * Constructs a new {@code WayData} with given id.
27 * @param id id
28 * @since 12017
29 */
30 public WayData(long id) {
31 super(id);
32 }
33
34 /**
35 * Constructs a new {@code WayData}.
36 * @param data way data to copy
37 */
38 public WayData(WayData data) {
39 super(data);
40 nodes.addAll(data.getNodes());
41 }
42
43 /**
44 * Gets a list of nodes the way consists of
45 * @return The ids of the nodes
46 */
47 public List<Long> getNodes() {
48 return Collections.unmodifiableList(nodes);
49 }
50
51 @Override
52 public int getNodesCount() {
53 return nodes.size();
54 }
55
56 @Override
57 public long getNodeId(int idx) {
58 return nodes.get(idx);
59 }
60
61 @Override
62 public boolean isClosed() {
63 if (isIncomplete()) return false;
64 return nodes.get(0).equals(nodes.get(nodes.size() - 1));
65 }
66
67 /**
68 * Sets the nodes array
69 * @param nodes The nodes this way consists of
70 */
71 public void setNodes(List<Long> nodes) {
72 this.nodes = new ArrayList<>(nodes);
73 }
74
75 @Override
76 public WayData makeCopy() {
77 return new WayData(this);
78 }
79
80 @Override
81 public String toString() {
82 return super.toString() + " WAY" + nodes;
83 }
84
85 @Override
86 public OsmPrimitiveType getType() {
87 return OsmPrimitiveType.WAY;
88 }
89
90 @Override
91 public void accept(PrimitiveVisitor visitor) {
92 visitor.visit(this);
93 }
94
95}
Note: See TracBrowser for help on using the repository browser.