Changeset 1754 in josm
- Timestamp:
- 2009-07-09T09:08:17+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1750 r1754 327 327 } 328 328 329 private class NodeCompare implements java.util.Comparator<Node>330 {331 public int compare(Node a, Node b)332 {333 int result = 0;334 335 if ((a.id == 0) && (b.id == 0))336 {337 if (a.getCoor().lat() == b.getCoor().lat())338 {339 result = Double.compare(a.getCoor().lon(), b.getCoor().lon());340 }341 else342 {343 result = Double.compare(a.getCoor().lat(), b.getCoor().lat());344 }345 }346 else347 {348 result = a.compareTo(b);349 }350 351 return result;352 }353 }354 355 329 private void sort() { 356 java.util. TreeMap<Node, java.util.TreeSet<Integer>> points =357 new java.util. TreeMap<Node, java.util.TreeSet<Integer>>(new NodeCompare());358 java.util. TreeMap<Node, Integer> nodes =359 new java.util. TreeMap<Node, Integer>(new NodeCompare());330 java.util.HashMap<Node, java.util.TreeSet<Integer>> points = 331 new java.util.HashMap<Node, java.util.TreeSet<Integer>>(); 332 java.util.HashMap<Node, Integer> nodes = 333 new java.util.HashMap<Node, Integer>(); 360 334 int i; 361 335 boolean lastWayStartUsed = true; … … 444 418 catch(java.util.NoSuchElementException e) {} 445 419 446 if ( m2 == null)420 if ((m2 == null) && ((i+1) < clone.members.size())) 447 421 { 448 422 // TODO: emit some message that sorting failed 449 423 System.err.println("relation member sort: could not find linked way or node for member " + i); 450 System.err.println("last way start used = " + lastWayStartUsed);451 424 break; 452 425 } … … 462 435 { 463 436 } 464 } 465 466 if ((m2 < clone.members.size()) && ((i+1) < clone.members.size())) 467 { 468 RelationMember a = clone.members.get(i+1); 469 RelationMember b = clone.members.get(m2); 470 471 if (m2 != (i+1)) 472 { 473 System.err.println("swapping " + (i+1) + " and " + m2); 474 clone.members.set(i+1, b); 475 clone.members.set(m2, a); 476 437 438 if ((m2 < clone.members.size()) && ((i+1) < clone.members.size())) 439 { 440 RelationMember a = clone.members.get(i+1); 441 RelationMember b = clone.members.get(m2); 442 443 if (m2 != (i+1)) 444 { 445 clone.members.set(i+1, b); 446 clone.members.set(m2, a); 447 448 try 449 { 450 if (!points.get(((Way)b.member).firstNode()).remove(m2)) 451 { 452 System.err.println("relation member sort: could not remove start mapping for " + m2); 453 } 454 if (!points.get(((Way)b.member).lastNode()).remove(m2)) 455 { 456 System.err.println("relation member sort: could not remove end mapping for " + m2); 457 } 458 } 459 catch(ClassCastException e1) 460 { 461 nodes.remove(b.member); 462 } 463 464 try 465 { 466 points.get(((Way)a.member).firstNode()).add(m2); 467 points.get(((Way)a.member).lastNode()).add(m2); 468 } 469 catch(ClassCastException e1) 470 { 471 nodes.put((Node)a.member, m2); 472 } 473 } 477 474 try 478 475 { 479 if (!points.get(((Way) b.member).firstNode()).remove(m2))476 if (!points.get(((Way)a.member).firstNode()).remove(i+1)) 480 477 { 481 System.err.println("relation member sort: could not remove start mapping for " + m2);482 } 483 if (!points.get(((Way) b.member).lastNode()).remove(m2))478 System.err.println("relation member sort: could not remove start mapping for " + (i+1)); 479 } 480 if (!points.get(((Way)a.member).lastNode()).remove(i+1)) 484 481 { 485 System.err.println("relation member sort: could not remove end mapping for " + m2);482 System.err.println("relation member sort: could not remove end mapping for " + (i+1)); 486 483 } 487 484 } 488 485 catch(ClassCastException e1) 489 486 { 490 nodes.remove(b.member); 491 } 492 493 try 494 { 495 points.get(((Way)a.member).firstNode()).add(m2); 496 points.get(((Way)a.member).lastNode()).add(m2); 497 } 498 catch(ClassCastException e1) 499 { 500 nodes.put((Node)a.member, m2); 501 } 502 } 503 try 504 { 505 if (!points.get(((Way)a.member).firstNode()).remove(i+1)) 506 { 507 System.err.println("relation member sort: could not remove start mapping for " + (i+1)); 508 } 509 if (!points.get(((Way)a.member).lastNode()).remove(i+1)) 510 { 511 System.err.println("relation member sort: could not remove end mapping for " + (i+1)); 512 } 513 } 514 catch(ClassCastException e1) 515 { 516 nodes.remove(a.member); 487 nodes.remove(a.member); 488 } 517 489 } 518 490 }
Note:
See TracChangeset
for help on using the changeset viewer.