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

Last change on this file since 2686 was 2686, checked in by Gubaer, 14 years ago

Partial commit due to issue described in #4137
Breaks the build

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