- Timestamp:
- 2010-03-23T21:12:35+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
r3151 r3154 11 11 import org.openstreetmap.josm.data.coor.QuadTiling; 12 12 13 /** 14 * Note: bbox of primitives added to QuadBuckets has to stay the same. In case of coordinate change, primitive must 15 * be removed and readded. 16 * 17 */ 13 18 public class QuadBuckets<T extends OsmPrimitive> implements Collection<T> 14 19 { … … 127 132 // changes made by threads will show up in children array too late, leading to QBLevel with all children 128 133 // set to null 134 if (content == null) 135 return false; 129 136 boolean ret = this.content.remove(o); 130 137 if (this.content.size() == 0) { … … 194 201 } 195 202 if (!hasChildren()) { 196 // All items stay at this level (get_index == 1). Create at least first child to keep the contract203 // All items stay at this level (get_index == -1). Create at least first child to keep the contract 197 204 // that at least one child always exists 198 205 children[0] = new QBLevel(this, 0); … … 378 385 return ret; 379 386 } 380 boolean contains(T n)381 {382 QBLevel res = find_exact(n);383 if (res == null)384 return false;385 return true;386 }387 QBLevel find_exact(T n)388 {389 if (content != null && content.contains(n))390 return this;391 return find_exact_child(n);392 }393 private QBLevel find_exact_child(T n)394 {395 QBLevel ret = null;396 if (children == null)397 return ret;398 for (QBLevel l : children) {399 if (l == null) {400 continue;401 }402 ret = l.find_exact(n);403 if (ret != null) {404 break;405 }406 }407 return ret;408 }409 387 410 388 void doAdd(T o) { … … 615 593 { 616 594 boolean changed = false; 617 for ( Objecto : objects) {618 changed = changed | this.add( convert(o));595 for (T o : objects) { 596 changed = changed | this.add(o); 619 597 } 620 598 return changed; … … 639 617 return this.remove(convert(o)); 640 618 } 641 private boolean remove_slow(T removeme) 642 { 643 boolean ret = false; 644 Iterator<T> i = this.iterator(); 645 while (i.hasNext()) { 646 T o = i.next(); 647 if (o != removeme) { 648 continue; 649 } 650 i.remove(); 651 ret = true; 652 break; 653 } 654 if (debug) { 655 out("qb slow remove result: " + ret); 656 } 657 return ret; 658 } 659 public boolean remove(T o) 660 { 661 /* 662 * We first try a locational search 663 */ 664 QBLevel bucket = root.find_exact(o); 665 /* 666 * That may fail because the object was 667 * moved or changed in some way, so we 668 * resort to an iterative search: 669 */ 670 if (bucket == null) 671 return remove_slow(o); 672 boolean ret = bucket.remove_content(o); 673 if (debug) { 674 out("qb remove result: " + ret); 675 } 619 public boolean remove(T o) { 676 620 search_cache = null; // Search cache might point to one of removed buckets 677 return ret; 678 } 679 public boolean contains(Object o) 680 { 681 QBLevel bucket = root.find_exact(convert(o)); 682 if (bucket == null) 683 return false; 684 return true; 685 } 621 QBLevel bucket = root.findBucket(o.getBBox()); 622 return bucket.remove_content(o); 623 } 624 public boolean contains(Object o) { 625 QBLevel bucket = root.findBucket(convert(o).getBBox()); 626 return bucket != null && bucket.content != null && bucket.content.contains(o); 627 } 628 686 629 public ArrayList<T> toArrayList() 687 630 {
Note:
See TracChangeset
for help on using the changeset viewer.