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

Last change on this file since 13764 was 13764, checked in by Don-vip, 6 years ago

add OsmData interface, abstraction of DataSet

  • Property svn:eol-style set to native
File size: 2.3 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
9/**
10 * The data (tags and node ids) that is stored for a way in the database
11 */
12public class WayData extends PrimitiveData implements IWay<NodeData> {
13
14 private static final long serialVersionUID = 106944939313286415L;
15 private List<Long> nodes = new ArrayList<>();
16
17 /**
18 * Constructs a new {@code NodeData}.
19 */
20 public WayData() {
21 // contents can be set later with setters
22 }
23
24 /**
25 * Constructs a new {@code WayData} with given id.
26 * @param id id
27 * @since 12017
28 */
29 public WayData(long id) {
30 super(id);
31 }
32
33 /**
34 * Constructs a new {@code WayData}.
35 * @param data way data to copy
36 */
37 public WayData(WayData data) {
38 super(data);
39 nodes.addAll(data.getNodeIds());
40 }
41
42 @Override
43 public List<NodeData> getNodes() {
44 throw new UnsupportedOperationException("Use getNodeIds() instead");
45 }
46
47 @Override
48 public NodeData getNode(int index) {
49 throw new UnsupportedOperationException("Use getNodeId(int) instead");
50 }
51
52 @Override
53 public List<Long> getNodeIds() {
54 return nodes;
55 }
56
57 @Override
58 public int getNodesCount() {
59 return nodes.size();
60 }
61
62 @Override
63 public long getNodeId(int idx) {
64 return nodes.get(idx);
65 }
66
67 @Override
68 public boolean isClosed() {
69 if (isIncomplete()) return false;
70 return nodes.get(0).equals(nodes.get(nodes.size() - 1));
71 }
72
73 /**
74 * Sets the nodes array
75 * @param nodes The nodes this way consists of
76 */
77 public void setNodes(List<Long> nodes) {
78 this.nodes = new ArrayList<>(nodes);
79 }
80
81 @Override
82 public WayData makeCopy() {
83 return new WayData(this);
84 }
85
86 @Override
87 public String toString() {
88 return super.toString() + " WAY" + nodes;
89 }
90
91 @Override
92 public OsmPrimitiveType getType() {
93 return OsmPrimitiveType.WAY;
94 }
95
96 @Override
97 public void accept(PrimitiveVisitor visitor) {
98 visitor.visit(this);
99 }
100
101 @Override
102 public BBox getBBox() {
103 throw new UnsupportedOperationException();
104 }
105}
Note: See TracBrowser for help on using the repository browser.