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

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

add IWay.setNodes()

  • Property svn:eol-style set to native
File size: 2.5 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 @Override
74 public void setNodes(List<NodeData> nodes) {
75 throw new UnsupportedOperationException("Use setNodeIds(List) instead");
76 }
77
78 /**
79 * Sets the nodes array
80 * @param nodes The nodes this way consists of
81 * @since 13907
82 */
83 public void setNodeIds(List<Long> nodes) {
84 this.nodes = new ArrayList<>(nodes);
85 }
86
87 @Override
88 public WayData makeCopy() {
89 return new WayData(this);
90 }
91
92 @Override
93 public String toString() {
94 return super.toString() + " WAY" + nodes;
95 }
96
97 @Override
98 public OsmPrimitiveType getType() {
99 return OsmPrimitiveType.WAY;
100 }
101
102 @Override
103 public void accept(PrimitiveVisitor visitor) {
104 visitor.visit(this);
105 }
106
107 @Override
108 public BBox getBBox() {
109 throw new UnsupportedOperationException();
110 }
111}
Note: See TracBrowser for help on using the repository browser.