Changeset 2423 in josm
- Timestamp:
- 2009-11-09T23:58:58+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
r2420 r2423 17 17 { 18 18 public static boolean debug = false; 19 static boolean consistency_testing = false;19 static boolean consistency_testing = true; 20 20 21 21 static void abort(String s) … … 247 247 this.content = null; 248 248 } 249 if (this.canRemove()) 250 this.remove_from_parent(); 249 251 return ret; 250 252 } … … 365 367 } 366 368 if (level >= NR_LEVELS-1) { 367 out("can not split, but too deep: " + level + " size: " + content.size()); 369 if (debug) 370 out("can not split, but too deep: " + level + " size: " + content.size()); 368 371 return; 369 372 } … … 484 487 return true; 485 488 } 489 QBLevel nextSibling() 490 { 491 QBLevel next = this; 492 QBLevel sibling = next.next_sibling(); 493 // Walk back up the tree to find the 494 // next sibling node. It may be either 495 // a leaf or branch. 496 while (sibling == null) { 497 if (debug) { 498 out("no siblings at level["+next.level+"], moving to parent"); 499 } 500 next = next.parent; 501 if (next == null) { 502 break; 503 } 504 sibling = next.next_sibling(); 505 } 506 next = sibling; 507 return next; 508 } 486 509 QBLevel nextContentNode() 487 510 { 488 511 QBLevel next = this; 489 if (this.isLeaf()) { 490 QBLevel sibling = next.next_sibling(); 491 // Walk back up the tree to find the 492 // next sibling node. It may be either 493 // a leaf or branch. 494 while (sibling == null) { 495 if (debug) { 496 out("no siblings at level["+next.level+"], moving to parent"); 497 } 498 next = next.parent; 499 if (next == null) { 500 break; 501 } 502 sibling = next.next_sibling(); 503 } 504 next = sibling; 505 } 512 if (this.isLeaf()) 513 next = this.nextSibling(); 506 514 if (next == null) 507 515 return null; 508 // all branches are guaranteed to have 509 // at least one leaf. It may not have 510 // any contents, but there *will* be a 511 // leaf. So, walk back down the tree 516 // Walk back down the tree 512 517 // and find the first leaf 513 while ( !next.isLeaf()) {514 if (next.hasContent() && next != this) {518 while (next != null && !next.isLeaf()) { 519 if (next.hasContent() && next != this) 515 520 break; 516 } 517 if (debug) { 521 if (debug) 518 522 out("["+next.level+"] next node ("+next+") is a branch (content: "+next.hasContent()+"), moving down..."); 519 }523 boolean progress = false; 520 524 for (QBLevel child : next.children) { 521 if (child == null) {525 if (child == null) 522 526 continue; 523 }524 527 next = child; 528 progress = true; 525 529 break; 526 530 } 527 } 531 if (!progress) { 532 // this should out it as not being a branch 533 next.children = null; 534 break; 535 } 536 } 537 // This means that there are no leaves or branches 538 // with content as children. We must continue to 539 // search siblings. 540 if (next == this) 541 return nextSibling().nextContentNode(); 528 542 return next; 529 543 } … … 784 798 return QuadTiling.tile2LatLon(this.quad); 785 799 } 800 void remove_from_parent() 801 { 802 if (parent == null) 803 return; 804 805 int nr_siblings = 0; 806 for (int i = 0; i < parent.children.length; i++) { 807 QBLevel sibling = parent.children[i]; 808 if (sibling != null) 809 nr_siblings++; 810 if (sibling != this) 811 continue; 812 if (this.content != null || 813 this.children != null) 814 abort("attempt to remove non-empty child"); 815 parent.children[i] = null; 816 nr_siblings--; 817 } 818 if (parent.canRemove()) 819 parent.remove_from_parent(); 820 } 821 boolean canRemove() 822 { 823 if (content != null && content.size() > 0) 824 return false; 825 if (children != null) { 826 for (QBLevel child : children) { 827 if (child != null) 828 return false; 829 } 830 } 831 return true; 832 } 786 833 } 787 834 … … 1073 1120 // an element 1074 1121 content_index--; 1075 peek(); //TODO Is the call to peek() necessary?1076 current_node. content.remove(content_index);1122 T object = peek(); //TODO Is the call to peek() necessary? 1123 current_node.remove_content(object); 1077 1124 } 1078 1125 }
Note:
See TracChangeset
for help on using the changeset viewer.