source: josm/trunk/src/org/openstreetmap/josm/data/osm/history/HistoryWay.java@ 5339

Last change on this file since 5339 was 5266, checked in by bastiK, 12 years ago

fixed majority of javadoc warnings by replacing "{@see" by "{@link"

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm.history;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.ArrayList;
7import java.util.Collections;
8import java.util.Date;
9import java.util.List;
10
11import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
12import org.openstreetmap.josm.data.osm.User;
13import org.openstreetmap.josm.data.osm.Way;
14
15/**
16 * Represents an immutable OSM way in the context of a historical view on
17 * OSM data.
18 *
19 */
20public class HistoryWay extends HistoryOsmPrimitive {
21
22 private ArrayList<Long> nodeIds = new ArrayList<Long>();
23
24 public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp) {
25 super(id, version, visible, user, changesetId, timestamp);
26 }
27
28 public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp, ArrayList<Long> nodeIdList) {
29 this(id, version, visible, user, changesetId, timestamp);
30 this.nodeIds.addAll(nodeIdList);
31 }
32
33 public HistoryWay(Way p) {
34 super(p);
35 }
36
37 /**
38 * replies the number of nodes in this way
39 * @return the number of nodes
40 */
41 public int getNumNodes() {
42 return nodeIds.size();
43 }
44
45 /**
46 * replies the idx-th node id in the list of node ids of this way
47 *
48 * @param idx the index
49 * @return the idx-th node id
50 * @exception IndexOutOfBoundsException thrown, if idx <0 || idx >= {#see {@link #getNumNodes()}
51 */
52 public long getNodeId(int idx) throws IndexOutOfBoundsException {
53 if (idx < 0 || idx >= nodeIds.size())
54 throw new IndexOutOfBoundsException(tr("Parameter {0} not in range 0..{1}. Got ''{2}''.", "idx", nodeIds.size(),idx));
55 return nodeIds.get(idx);
56 }
57
58 /**
59 * replies an immutable list of the ways node ids
60 *
61 * @return the ways node ids
62 */
63 public List<Long> getNodes() {
64 return Collections.unmodifiableList(nodeIds);
65 }
66
67 /**
68 * replies the ways type, i.e. {@link OsmPrimitiveType#WAY}
69 *
70 * @return the ways type
71 */
72 @Override
73 public OsmPrimitiveType getType() {
74 return OsmPrimitiveType.WAY;
75 }
76
77 /**
78 * adds a node id to the list nodes of this way
79 *
80 * @param ref the node id to add
81 */
82 public void addNode(long ref) {
83 nodeIds.add(ref);
84 }
85
86 /**
87 * Replies true if this way is closed.
88 *
89 * @return true if this way is closed.
90 */
91 public boolean isClosed() {
92 return getNumNodes() >= 3 && nodeIds.get(0) == nodeIds.get(nodeIds.size()-1);
93 }
94
95 @Override
96 public String getDisplayName(HistoryNameFormatter formatter) {
97 return formatter.format(this);
98 }
99}
Note: See TracBrowser for help on using the repository browser.