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

Last change on this file since 12116 was 12017, checked in by Don-vip, 7 years ago

*Data: new constructors with a given id

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