Changeset 5408 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2012-08-08T22:37:36+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r5266 r5408 19 19 20 20 /** 21 * One full way, consisting of a list of way nodes.21 * One full way, consisting of a list of way {@link Node nodes}. 22 22 * 23 23 * @author imi 24 * @since 64 24 25 */ 25 26 public final class Way extends OsmPrimitive implements IWay { … … 128 129 * @return true if this way contains the node <code>node</code>, false 129 130 * otherwise 130 * @since 19 09131 * @since 1911 131 132 */ 132 133 public boolean containsNode(Node node) { … … 146 147 * @param node the node. May be null. 147 148 * @return Set of nodes adjacent to <code>node</code> 148 * @since 46 66149 * @since 4671 149 150 */ 150 151 public Set<Node> getNeighbours(Node node) { … … 165 166 } 166 167 168 /** 169 * Replies the ordered {@link List} of chunks of this way. Each chunk is replied as a {@link Pair} of {@link Node nodes}. 170 * @param sort If true, the nodes of each pair are sorted as defined by {@link Pair#sort}. 171 * If false, Pair.a and Pair.b are in the way order (i.e for a given Pair(n), Pair(n-1).b == Pair(n).a, Pair(n).b == Pair(n+1).a, etc.) 172 * @return The ordered list of chunks of this way. 173 * @since 3348 174 */ 167 175 public List<Pair<Node,Node>> getNodePairs(boolean sort) { 168 176 List<Pair<Node,Node>> chunkSet = new ArrayList<Pair<Node,Node>>(); … … 198 206 199 207 /** 200 * C reates a newwaywith id 0.201 * 202 */ 203 public Way(){ 208 * Contructs a new {@code Way} with id 0. 209 * @since 86 210 */ 211 public Way() { 204 212 super(0, false); 205 213 } 206 214 207 215 /** 208 * 209 * @param original 210 * @param clearId 216 * Contructs a new {@code Way} from an existing {@code Way}. 217 * @param original The original {@code Way} to be identically cloned. Must not be null 218 * @param clearId If true, clears the OSM id as defined by {@link #clearOsmId}. If false, does nothing 219 * @since 2410 211 220 */ 212 221 public Way(Way original, boolean clearId) { … … 219 228 220 229 /** 221 * C reate an identical clone of the argument(includingtheid).222 * 223 * @ param original the original way. Must not be null.230 * Contructs a new {@code Way} from an existing {@code Way} (including its id). 231 * @param original The original {@code Way} to be identically cloned. Must not be null 232 * @since 86 224 233 */ 225 234 public Way(Way original) { … … 228 237 229 238 /** 230 * C reates a newwayfor the given id. If the id > 0, the way is marked239 * Contructs a new {@code Way} for the given id. If the id > 0, the way is marked 231 240 * as incomplete. If id == 0 then way is marked as new 232 241 * 233 242 * @param id the id. >= 0 required 234 * @throws IllegalArgumentException thrown if id < 0 243 * @throws IllegalArgumentException if id < 0 244 * @since 343 235 245 */ 236 246 public Way(long id) throws IllegalArgumentException { … … 239 249 240 250 /** 241 * Creates new way with given id and version. 242 * @param id 243 * @param version 244 */ 245 public Way(long id, int version) { 251 * Contructs a new {@code Way} with given id and version. 252 * @param id the id. >= 0 required 253 * @param version the version 254 * @throws IllegalArgumentException if id < 0 255 * @since 2620 256 */ 257 public Way(long id, int version) throws IllegalArgumentException { 246 258 super(id, version, false); 247 259 } 248 260 249 /**250 *251 * @param data252 */253 261 @Override 254 262 public void load(PrimitiveData data) { … … 273 281 } 274 282 275 @Override public WayData save() { 283 @Override 284 public WayData save() { 276 285 WayData data = new WayData(); 277 286 saveCommonAttributes(data); … … 282 291 } 283 292 284 @Override public void cloneFrom(OsmPrimitive osm) { 293 @Override 294 public void cloneFrom(OsmPrimitive osm) { 285 295 boolean locked = writeLock(); 286 296 try { … … 293 303 } 294 304 295 @Override public String toString() { 305 @Override 306 public String toString() { 296 307 String nodesDesc = isIncomplete()?"(incomplete)":"nodes=" + Arrays.toString(nodes); 297 308 return "{Way id=" + getUniqueId() + " version=" + getVersion()+ " " + getFlagsAsString() + " " + nodesDesc + "}"; … … 320 331 } 321 332 333 /** 334 * Removes the given {@link Node} from this way. Ignored, if n is null. 335 * @param n The node to remove. Ignored, if null 336 * @since 1463 337 */ 322 338 public void removeNode(Node n) { 323 if (isIncomplete()) return; 339 if (n == null || isIncomplete()) return; 324 340 boolean locked = writeLock(); 325 341 try { … … 342 358 } 343 359 344 public void removeNodes(Set<? extends OsmPrimitive> selection) { 345 if (isIncomplete()) return; 360 /** 361 * Removes the given set of {@link Node nodes} from this way. Ignored, if selection is null. 362 * @param selection The selection of nodes to remove. Ignored, if null 363 * @since 5408 364 */ 365 public void removeNodes(Set<? extends Node> selection) { 366 if (selection == null || isIncomplete()) return; 346 367 boolean locked = writeLock(); 347 368 try { … … 370 391 * Adds a node to the end of the list of nodes. Ignored, if n is null. 371 392 * 372 * @param n the node. Ignored, if null .393 * @param n the node. Ignored, if null 373 394 * @throws IllegalStateException thrown, if this way is marked as incomplete. We can't add a node 374 395 * to an incomplete way 396 * @since 1313 375 397 */ 376 398 public void addNode(Node n) throws IllegalStateException { … … 396 418 * Adds a node at position offs. 397 419 * 398 * @param intoffs the offset420 * @param offs the offset 399 421 * @param n the node. Ignored, if null. 400 422 * @throws IllegalStateException thrown, if this way is marked as incomplete. We can't add a node 401 423 * to an incomplete way 402 424 * @throws IndexOutOfBoundsException thrown if offs is out of bounds 425 * @since 1313 403 426 */ 404 427 public void addNode(int offs, Node n) throws IllegalStateException, IndexOutOfBoundsException { … … 453 476 * The result equals <tt>{@link #getNode getNode}({@link #getNodesCount getNodesCount} - 1)</tt>. 454 477 * @return the last node of this way 478 * @since 1400 455 479 */ 456 480 public Node lastNode() { … … 464 488 * The result equals {@link #getNode getNode}{@code (0)}. 465 489 * @return the first node of this way 490 * @since 1400 466 491 */ 467 492 public Node firstNode() { … … 471 496 } 472 497 498 /** 499 * Replies true if the given node is the first or the last one of this way, false otherwise. 500 * @param n The node to test 501 * @return true if the {@code n} is the first or the last node, false otherwise. 502 * @since 1400 503 */ 473 504 public boolean isFirstLastNode(Node n) { 474 505 Node[] nodes = this.nodes; … … 477 508 } 478 509 510 /** 511 * Replies true if the given node is an inner node of this way, false otherwise. 512 * @param n The node to test 513 * @return true if the {@code n} is an inner node, false otherwise. 514 * @since 3515 515 */ 479 516 public boolean isInnerNode(Node n) { 480 517 Node[] nodes = this.nodes; … … 482 519 /* circular ways have only inner nodes, so return true for them! */ 483 520 if (n == nodes[0] && n == nodes[nodes.length-1]) return true; 484 for(int i = 1; i < nodes.length - 1; ++i) { 485 if(nodes[i] == n) return true; 521 for (int i = 1; i < nodes.length - 1; ++i) { 522 if (nodes[i] == n) return true; 486 523 } 487 524 return false; 488 525 } 489 526 490 527 @Override 491 528 public String getDisplayName(NameFormatter formatter) { 492 529 return formatter.format(this); … … 517 554 if (Main.pref.getBoolean("debug.checkNullCoor", true)) { 518 555 for (Node n: nodes) { 519 if (!n.isIncomplete() && (n.getCoor() == null || n.getEastNorth() == null)) 520 throw new DataIntegrityProblemException("Complete node with null coordinates: " + toString() + n.get3892DebugInfo(), 556 if (n.isVisible() && !n.isIncomplete() && (n.getCoor() == null || n.getEastNorth() == null)) 557 throw new DataIntegrityProblemException("Complete visible node with null coordinates: " + toString() + n.get3892DebugInfo(), 521 558 "<html>" + tr("Complete node {0} with null coordinates in way {1}", 522 559 DefaultNameFormatter.getInstance().formatAsHtmlUnorderedList(n), … … 555 592 } 556 593 594 /** 595 * Replies true if this way has incomplete nodes, false otherwise. 596 * @return true if this way has incomplete nodes, false otherwise. 597 * @since 2587 598 */ 557 599 public boolean hasIncompleteNodes() { 558 600 Node[] nodes = this.nodes; 559 for (Node node :nodes) {601 for (Node node : nodes) { 560 602 if (node.isIncomplete()) 561 603 return true; … … 574 616 } 575 617 576 577 /* since revision 4138 */ 618 /** 619 * Replies the length of the way, in metres, as computed by {@link LatLon#greatCircleDistance}. 620 * @return The length of the way, in metres 621 * @since 4138 622 */ 578 623 public double getLength() { 579 624 double length = 0; … … 594 639 /** 595 640 * Tests if this way is a oneway. 596 * @return {@code 1} if the way is a oneway, {@code -1} if the way is a reversed oneway, 597 * {@code 0} otherwise. 641 * @return {@code 1} if the way is a oneway, 642 * {@code -1} if the way is a reversed oneway, 643 * {@code 0} otherwise. 644 * @since 5199 598 645 */ 599 646 public int isOneway() { … … 612 659 } 613 660 661 /** 662 * Replies the first node of this way, respecting or not its oneway state. 663 * @param respectOneway If true and if this way is a oneway, replies the last node. Otherwise, replies the first node. 664 * @return the first node of this way, according to {@code respectOneway} and its oneway state. 665 * @since 5199 666 */ 614 667 public Node firstNode(boolean respectOneway) { 615 668 return !respectOneway || isOneway() != -1 ? firstNode() : lastNode(); 616 669 } 617 670 671 /** 672 * Replies the last node of this way, respecting or not its oneway state. 673 * @param respectOneway If true and if this way is a oneway, replies the first node. Otherwise, replies the last node. 674 * @return the last node of this way, according to {@code respectOneway} and its oneway state. 675 * @since 5199 676 */ 618 677 public Node lastNode(boolean respectOneway) { 619 678 return !respectOneway || isOneway() != -1 ? lastNode() : firstNode();
Note:
See TracChangeset
for help on using the changeset viewer.