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

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

sonar - squid:RedundantThrowsDeclarationCheck - Throws declarations should not be superfluous

  • Property svn:eol-style set to native
File size: 5.1 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;
14import org.openstreetmap.josm.tools.CheckParameterUtil;
15
16/**
17 * Represents an immutable OSM way in the context of a historical view on
18 * OSM data.
19 *
20 */
21public class HistoryWay extends HistoryOsmPrimitive {
22
23 private final List<Long> nodeIds = new ArrayList<>();
24
25 /**
26 * Constructs a new {@code HistoryWay}.
27 *
28 * @param id the id (&gt; 0 required)
29 * @param version the version (&gt; 0 required)
30 * @param visible whether the node is still visible
31 * @param user the user (!= null required)
32 * @param changesetId the changeset id (&gt; 0 required if {@code checkHistoricParams} is true)
33 * @param timestamp the timestamp (!= null required if {@code checkHistoricParams} is true)
34 * @throws IllegalArgumentException if preconditions are violated
35 */
36 public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp) {
37 super(id, version, visible, user, changesetId, timestamp);
38 }
39
40 /**
41 * Constructs a new {@code HistoryWay} with a configurable checking of historic parameters.
42 * This is needed to build virtual HistoryWays for modified ways, which do not have a timestamp and a changeset id.
43 *
44 * @param id the id (&gt; 0 required)
45 * @param version the version (&gt; 0 required)
46 * @param visible whether the node is still visible
47 * @param user the user (!= null required)
48 * @param changesetId the changeset id (&gt; 0 required if {@code checkHistoricParams} is true)
49 * @param timestamp the timestamp (!= null required if {@code checkHistoricParams} is true)
50 * @param checkHistoricParams if true, checks values of {@code changesetId} and {@code timestamp}
51 * @throws IllegalArgumentException if preconditions are violated
52 * @since 5440
53 */
54 public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp, boolean checkHistoricParams) {
55 super(id, version, visible, user, changesetId, timestamp, checkHistoricParams);
56 }
57
58 /**
59 * Constructs a new {@code HistoryWay} with a given list of node ids.
60 *
61 * @param id the id (&gt; 0 required)
62 * @param version the version (&gt; 0 required)
63 * @param visible whether the node is still visible
64 * @param user the user (!= null required)
65 * @param changesetId the changeset id (&gt; 0 required if {@code checkHistoricParams} is true)
66 * @param timestamp the timestamp (!= null required if {@code checkHistoricParams} is true)
67 * @param nodeIdList the node ids (!= null required)
68 * @throws IllegalArgumentException if preconditions are violated
69 */
70 public HistoryWay(long id, long version, boolean visible, User user, long changesetId, Date timestamp, List<Long> nodeIdList) {
71 this(id, version, visible, user, changesetId, timestamp);
72 CheckParameterUtil.ensureParameterNotNull(nodeIdList, "nodeIdList");
73 this.nodeIds.addAll(nodeIdList);
74 }
75
76 /**
77 * Constructs a new {@code HistoryWay} from an existing {@link Way}.
78 * @param w the way
79 */
80 public HistoryWay(Way w) {
81 super(w);
82 }
83
84 /**
85 * replies the number of nodes in this way
86 * @return the number of nodes
87 */
88 public int getNumNodes() {
89 return nodeIds.size();
90 }
91
92 /**
93 * replies the idx-th node id in the list of node ids of this way
94 *
95 * @param idx the index
96 * @return the idx-th node id
97 * @throws IndexOutOfBoundsException if idx &lt; 0 || idx &gt;= {#see {@link #getNumNodes()}
98 */
99 public long getNodeId(int idx) {
100 if (idx < 0 || idx >= nodeIds.size())
101 throw new IndexOutOfBoundsException(tr("Parameter {0} not in range 0..{1}. Got ''{2}''.", "idx", nodeIds.size(), idx));
102 return nodeIds.get(idx);
103 }
104
105 /**
106 * replies an immutable list of the ways node ids
107 *
108 * @return the ways node ids
109 */
110 public List<Long> getNodes() {
111 return Collections.unmodifiableList(nodeIds);
112 }
113
114 /**
115 * replies the ways type, i.e. {@link OsmPrimitiveType#WAY}
116 *
117 * @return the ways type
118 */
119 @Override
120 public OsmPrimitiveType getType() {
121 return OsmPrimitiveType.WAY;
122 }
123
124 /**
125 * adds a node id to the list nodes of this way
126 *
127 * @param ref the node id to add
128 */
129 public void addNode(long ref) {
130 nodeIds.add(ref);
131 }
132
133 /**
134 * Replies true if this way is closed.
135 *
136 * @return true if this way is closed.
137 */
138 public boolean isClosed() {
139 return getNumNodes() >= 3 && nodeIds.get(0) == nodeIds.get(nodeIds.size()-1);
140 }
141
142 @Override
143 public String getDisplayName(HistoryNameFormatter formatter) {
144 return formatter.format(this);
145 }
146}
Note: See TracBrowser for help on using the repository browser.