Changeset 2388 in josm
- Timestamp:
- 2009-11-02T21:04:32+01:00 (15 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r2381 r2388 17 17 18 18 import org.openstreetmap.josm.data.SelectionChangedListener; 19 import org.openstreetmap.josm.data.osm.QuadBuckets.BBox; 19 20 20 21 /** … … 65 66 } 66 67 68 public List<Node> searchNodes(BBox bbox) { 69 return nodes.search(bbox); 70 } 71 67 72 /** 68 73 * All ways (Streets etc.) in the DataSet. … … 76 81 public Collection<Way> getWays() { 77 82 return Collections.unmodifiableCollection(ways); 83 } 84 85 public List<Way> searchWays(BBox bbox) { 86 return ways.search(bbox); 78 87 } 79 88 … … 438 447 DataSet ds = new DataSet(); 439 448 for (Node n : nodes) { 440 ds. nodes.add(new Node(n));449 ds.addPrimitive(new Node(n)); 441 450 } 442 451 for (Way w : ways) { 443 ds. ways.add(new Way(w));452 ds.addPrimitive(new Way(w)); 444 453 } 445 454 for (Relation e : relations) { 446 ds. relations.add(new Relation(e));455 ds.addPrimitive(new Relation(e)); 447 456 } 448 457 for (DataSource source : dataSources) { … … 667 676 return ret; 668 677 } 678 679 /** 680 * Reindex all nodes and ways after their coordinates were changed. This is a temporary solution, reindexing should 681 * be automatic in the future 682 */ 683 public void reindexAll() { 684 List<Node> ntmp = new ArrayList<Node>(nodes); 685 nodes.clear(); 686 nodes.addAll(ntmp); 687 List<Way> wtmp = new ArrayList<Way>(ways); 688 ways.clear(); 689 ways.addAll(wtmp); 690 } 691 692 public void clenupDeletedPrimitives() { 693 cleanupDeleted(nodes.iterator()); 694 cleanupDeleted(ways.iterator()); 695 cleanupDeleted(relations.iterator()); 696 } 697 698 private void cleanupDeleted(Iterator<? extends OsmPrimitive> it) { 699 while (it.hasNext()) { 700 if (it.next().isDeleted()) { 701 it.remove(); 702 } 703 } 704 } 669 705 } -
trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
r2380 r2388 4 4 import java.util.Collection; 5 5 import java.util.Collections; 6 import java.util.Set; 7 import java.util.SortedMap; 8 import java.util.TreeMap; 6 import java.util.HashMap; 7 import java.util.Iterator; 8 import java.util.LinkedList; 9 import java.util.List; 9 10 10 import org.openstreetmap.josm.data.coor.EastNorth; 11 import org.openstreetmap.josm.data.osm.Node; 12 import org.openstreetmap.josm.data.osm.Way; 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.tools.Pair; 15 16 import java.nio.MappedByteBuffer; 17 import java.nio.DoubleBuffer; 18 import java.nio.channels.FileChannel; 19 import java.io.FileOutputStream; 20 import java.io.RandomAccessFile; 21 22 import java.io.IOException; 23 import java.io.BufferedReader; 24 import java.io.InputStreamReader; 25 26 import java.util.Map.Entry; 27 import java.awt.geom.Point2D; 28 29 //import java.util.List; 30 import java.util.*; 31 import java.util.Collection; 32 11 import org.openstreetmap.josm.data.coor.LatLon; 33 12 import org.openstreetmap.josm.data.coor.QuadTiling; 34 import org.openstreetmap.josm.data.coor.EastNorth;35 import org.openstreetmap.josm.data.coor.LatLon;36 13 37 14 … … 65 42 long now = System.currentTimeMillis(); 66 43 if ((now - last_out < 300) && 67 ((i+1) < total))44 ((i+1) < total)) 68 45 return; 69 46 last_out = now; … … 82 59 public static int TILES_PER_LEVEL = 1<<TILES_PER_LEVEL_SHIFT; 83 60 // Maybe this should just be a Rectangle?? 84 class BBox61 public static class BBox 85 62 { 86 63 private double xmin = Double.POSITIVE_INFINITY; … … 90 67 void sanity() 91 68 { 92 if (xmin < -180.0) 69 if (xmin < -180.0) { 93 70 xmin = -180.0; 94 if (xmax > 180.0) 71 } 72 if (xmax > 180.0) { 95 73 xmax = 180.0; 96 if (ymin < -90.0) 74 } 75 if (ymin < -90.0) { 97 76 ymin = -90.0; 98 if (ymax > 90.0) 77 } 78 if (ymax > 90.0) { 99 79 ymax = 90.0; 80 } 100 81 if ((xmin < -180.0) || 101 (xmax > 180.0) ||102 (ymin < -90.0) ||103 (ymax > 90.0)) {82 (xmax > 180.0) || 83 (ymin < -90.0) || 84 (ymax > 90.0)) { 104 85 out("bad BBox: " + this); 105 86 Object o = null; … … 107 88 } 108 89 } 90 @Override 109 91 public String toString() 110 92 { 111 93 return "[ x: " + xmin + " -> " + xmax + 112 94 ", y: " + ymin + " -> " + ymax + " ]"; 113 95 } 114 96 double min(double a, double b) … … 149 131 for (Node n : w.getNodes()) { 150 132 LatLon coor = n.getCoor(); 151 if (coor == null) 133 if (coor == null) { 152 134 continue; 135 } 153 136 add(coor); 154 137 } … … 166 149 { 167 150 if (!(xmin <= b.xmin) || 168 !(xmax >= b.xmax) ||169 !(ymin <= b.ymin) ||170 !(ymax >= b.ymax))151 !(xmax >= b.xmax) || 152 !(ymin <= b.ymin) || 153 !(ymax >= b.ymax)) 171 154 return false; 172 155 return true; … … 175 158 { 176 159 if ((xmin <= c.lon()) && 177 (xmax >= c.lon()) &&178 (ymin <= c.lat()) &&179 (ymax >= c.lat()))160 (xmax >= c.lon()) && 161 (ymin <= c.lat()) && 162 (ymax >= c.lat())) 180 163 return true; 181 164 return false; … … 223 206 BBox way_bbox(Way w) 224 207 { 225 if (way_bbox_cache.size() > 100) 208 if (way_bbox_cache.size() > 100) { 226 209 way_bbox_cache.clear(); 210 } 227 211 BBox b = way_bbox_cache.get(w); 228 212 if (b == null) { … … 242 226 public List<T> content; 243 227 public QBLevel children[]; 228 @Override 244 229 public String toString() 245 230 { … … 263 248 { 264 249 boolean ret = this.content.remove(o); 265 if (this.content.size() == 0) 250 if (this.content.size() == 0) { 266 251 this.content = null; 252 } 267 253 return ret; 268 254 } … … 282 268 int get_index(T o, int level) 283 269 { 284 if (debug) 270 if (debug) { 285 271 out("getting index for " + o + " at level: " + level); 272 } 286 273 if (o instanceof Node) { 287 274 Node n = (Node)o; … … 296 283 //for (Node n : w.getNodes()) { 297 284 for (LatLon c : way_bbox(w).points()) { 298 // LatLon c = n.getCoor();299 if (debug) 285 // LatLon c = n.getCoor(); 286 if (debug) { 300 287 out("getting index for point: " + c); 288 } 301 289 if (index == -1) { 302 290 index = QuadTiling.index(c, level); 303 if (debug) 291 if (debug) { 304 292 out("set initial way index to: " + index); 293 } 305 294 continue; 306 295 } 307 296 int node_index = QuadTiling.index(c, level); 308 if (debug) 297 if (debug) { 309 298 out("other node way index: " + node_index); 299 } 310 300 if (node_index != index) { 311 301 // This happens at level 0 sometimes when a way has no … … 315 305 + node_index + "/" + index + " at level: " + level + " "); 316 306 out("node count: " + w.getNodes().size()); 317 for (LatLon c2 : way_bbox(w).points()) 307 for (LatLon c2 : way_bbox(w).points()) { 318 308 out("points: " + c2); 309 } 319 310 } 320 311 return -1; … … 328 319 void split() 329 320 { 330 if (debug) 321 if (debug) { 331 322 out("splitting "+this.bbox()+" level "+level+" with " 332 323 + content.size() + " entries (my dimensions: " 333 324 + this.bbox.width()+", "+this.bbox.height()+")"); 325 } 334 326 if (children != null) { 335 327 abort("overwrote children"); … … 349 341 continue; 350 342 } 351 if (children[new_index] == null) 343 if (children[new_index] == null) { 352 344 children[new_index] = new QBLevel(this, new_index); 345 } 353 346 QBLevel child = children[new_index]; 354 if (debug) 347 if (debug) { 355 348 out("putting "+o+"(q:"+quads(o)+") into ["+new_index+"] " + child.bbox()); 349 } 356 350 child.add(o); 357 351 } … … 360 354 { 361 355 boolean ret = false; 362 if (content == null) 356 if (content == null) { 363 357 content = new ArrayList<T>(); 358 } 364 359 ret = content.add(o); 365 if (debug && !this.isLeaf()) 360 if (debug && !this.isLeaf()) { 366 361 pout("added "+o.getClass().getName()+" to non-leaf with size: " + content.size()); 362 } 367 363 return ret; 368 364 } … … 372 368 add_content(o); 373 369 if (content.size() > MAX_OBJECTS_PER_LEVEL) { 374 if (debug) 370 if (debug) { 375 371 out("["+level+"] deciding to split"); 372 } 376 373 if (level >= NR_LEVELS-1) { 377 374 out("can not split, but too deep: " + level + " size: " + content.size()); … … 379 376 } 380 377 int before_size = -1; 381 if (consistency_testing) 378 if (consistency_testing) { 382 379 before_size = this.size(); 380 } 383 381 this.split(); 384 382 if (consistency_testing) { … … 410 408 { 411 409 String size = "null"; 412 if (content != null) 410 if (content != null) { 413 411 size = ""+content.size(); 414 if (debug) 412 } 413 if (debug) { 415 414 out("searching contents (size: "+size+") for " + search_bbox); 415 } 416 416 /* 417 417 * It is possible that this was created in a split … … 428 428 List<T> ret = new LinkedList<T>(); 429 429 for (T o : content) { 430 if (matches(o, search_bbox)) 430 if (matches(o, search_bbox)) { 431 431 ret.add(o); 432 } 433 if (debug) 432 } 433 } 434 if (debug) { 434 435 out("done searching quad " + Long.toHexString(this.quad)); 436 } 435 437 return ret; 436 438 } … … 457 459 int nr = __nr-1; 458 460 if (sibling == null) { 459 if (debug) 461 if (debug) { 460 462 out("[" + this.level + "] null child nr: " + nr); 463 } 461 464 continue; 462 465 } … … 464 467 // after us. 465 468 if (sibling == this) { 466 if (debug) 469 if (debug) { 467 470 out("[" + this.level + "] I was child nr: " + nr); 471 } 468 472 found_me = true; 469 473 continue; 470 474 } 471 475 if (found_me) { 472 if (debug) 476 if (debug) { 473 477 out("[" + this.level + "] next sibling was child nr: " + nr); 478 } 474 479 return sibling; 475 480 } 476 if (debug) 481 if (debug) { 477 482 out("[" + this.level + "] nr: " + nr + " is before me, ignoring..."); 483 } 478 484 } 479 485 return null; … … 494 500 // a leaf or branch. 495 501 while (sibling == null) { 496 if (debug) 502 if (debug) { 497 503 out("no siblings at level["+next.level+"], moving to parent"); 504 } 498 505 next = next.parent; 499 if (next == null) 506 if (next == null) { 500 507 break; 508 } 501 509 sibling = next.next_sibling(); 502 510 } … … 511 519 // and find the first leaf 512 520 while (!next.isLeaf()) { 513 if (next.hasContent() && next != this) 521 if (next.hasContent() && next != this) { 514 522 break; 515 if (debug) 523 } 524 if (debug) { 516 525 out("["+next.level+"] next node ("+next+") is a branch (content: "+next.hasContent()+"), moving down..."); 526 } 517 527 for (QBLevel child : next.children) { 518 if (child == null) 528 if (child == null) { 519 529 continue; 530 } 520 531 next = child; 521 532 break; … … 533 544 { 534 545 if (content == null) { 535 if (debug) 546 if (debug) { 536 547 out("["+level+"] leaf size: null content, children? " + children); 548 } 537 549 return 0; 538 550 } 539 if (debug) 551 if (debug) { 540 552 out("["+level+"] leaf size: " + content.size()); 553 } 541 554 return content.size(); 542 555 } … … 545 558 int ret = 0; 546 559 for (QBLevel l : children) { 547 if (l == null) 560 if (l == null) { 548 561 continue; 562 } 549 563 ret += l.size(); 550 564 } 551 if (content != null) 565 if (content != null) { 552 566 ret += content.size(); 553 if (debug) 567 } 568 if (debug) { 554 569 out("["+level+"] branch size: " + ret); 570 } 555 571 return ret; 556 572 } … … 575 591 return ret; 576 592 for (QBLevel l : children) { 577 if (l == null) 593 if (l == null) { 578 594 continue; 595 } 579 596 ret = l.find_exact(n); 580 if (ret != null) 597 if (ret != null) { 581 598 break; 599 } 582 600 } 583 601 return ret; … … 593 611 } 594 612 } 595 if (isLeaf()) 613 if (isLeaf()) { 596 614 add_to_leaf(n); 597 else615 } else { 598 616 add_to_branch(n); 617 } 599 618 return true; 600 619 } … … 603 622 int index = get_index(n, level); 604 623 if (index == -1) { 605 if (debug) 624 if (debug) { 606 625 out("unable to get index for " + n + "at level: " + level + ", adding content to branch: " + this); 626 } 607 627 this.add_content(n); 608 628 return this; … … 610 630 if (debug) { 611 631 out("[" + level + "]: " + n + 612 " index " + index + " levelquad:" + this.quads() + " level bbox:" + this.bbox());632 " index " + index + " levelquad:" + this.quads() + " level bbox:" + this.bbox()); 613 633 out(" put in child["+index+"]"); 614 634 } 615 if (children[index] == null) 635 if (children[index] == null) { 616 636 children[index] = new QBLevel(this, index); 637 } 617 638 children[index].add(n); 618 639 return this; … … 621 642 { 622 643 List<T> ret = null; 623 if (debug) 644 if (debug) { 624 645 System.out.print("[" + level + "] qb bbox: " + this.bbox() + " "); 646 } 625 647 if (!this.bbox().intersects(search_bbox)) { 626 648 if (debug) { … … 630 652 return ret; 631 653 } 632 if (this.hasContent()) 654 if (this.hasContent()) { 633 655 ret = this.search_contents(search_bbox); 634 if (this.isLeaf()) { 656 } 657 if (this.isLeaf()) 635 658 return ret; 636 }637 659 //if (this.hasContent()) 638 660 // abort("branch had stuff"); 639 if (debug) 661 if (debug) { 640 662 out("hit " + this.quads()); 663 } 641 664 642 if (debug) 665 if (debug) { 643 666 out("[" + level + "] not leaf, moving down"); 667 } 644 668 for (int i = 0; i < children.length; i++) { 645 669 QBLevel q = children[i]; 646 if (debug) 670 if (debug) { 647 671 out("child["+i+"]: " + q); 648 if (q == null) 672 } 673 if (q == null) { 649 674 continue; 650 if (debug) 675 } 676 if (debug) { 651 677 System.out.print(i+": "); 678 } 652 679 List<T> coors = q.search(search_bbox); 653 if (coors == null) 680 if (coors == null) { 654 681 continue; 655 if (ret == null) 682 } 683 if (ret == null) { 656 684 ret = coors; 657 else685 } else { 658 686 ret.addAll(coors); 687 } 659 688 if (q.bbox().bounds(search_bbox)) { 660 689 search_cache = q; … … 663 692 // what we were looking for. 664 693 if (coors.size() > 0 ) { 665 if (debug) 694 if (debug) { 666 695 out("break early"); 696 } 667 697 break; 668 698 } … … 677 707 public void init(QBLevel parent) 678 708 { 679 this.parent = parent; 680 if (parent == null) 681 this.level = 0; 682 else 683 this.level = parent.level + 1; 684 this.quad = 0; 709 this.parent = parent; 710 if (parent == null) { 711 this.level = 0; 712 } else { 713 this.level = parent.level + 1; 714 } 715 this.quad = 0; 685 716 } 686 717 int index_of(QBLevel find_this) … … 708 739 long this_quadpart = mult * (parent_index << shift); 709 740 this.quad = parent.quad | this_quadpart; 710 if (debug) 741 if (debug) { 711 742 out("new level["+this.level+"] bbox["+parent_index+"]: " + this.bbox() 712 743 + " coor: " + this.coor() 713 744 + " quadpart: " + Long.toHexString(this_quadpart) 714 745 + " quad: " + Long.toHexString(this.quad)); 746 } 715 747 } 716 748 /* … … 779 811 public boolean add(T n) 780 812 { 781 if (debug) 813 if (debug) { 782 814 out("QuadBuckets() add: " + n + " size now: " + this.size()); 815 } 783 816 int before_size = -1; 784 if (consistency_testing) 817 if (consistency_testing) { 785 818 before_size = root.size(); 819 } 786 820 boolean ret; 787 821 // A way with no nodes will have an infinitely large 788 822 // bounding box. Just stash it in the root node. 789 if (!n.isUsable()) 823 if (!n.isUsable()) { 790 824 ret = root.add_content(n); 791 else825 } else { 792 826 ret = root.add(n); 827 } 793 828 if (consistency_testing) { 794 829 int end_size = root.size(); 795 if (ret) 830 if (ret) { 796 831 end_size--; 797 if (before_size != end_size) 832 } 833 if (before_size != end_size) { 798 834 abort("size inconsistency before add: " + before_size + " after: " + end_size); 799 } 800 if (debug) 835 } 836 } 837 if (debug) { 801 838 out("QuadBuckets() add: " + n + " size after: " + this.size()); 839 } 802 840 return ret; 803 841 } … … 820 858 { 821 859 for (T o : this) { 822 if (objects.contains(o)) 860 if (objects.contains(o)) { 823 861 continue; 862 } 824 863 if (!this.remove(o)) 825 864 return false; … … 890 929 while (i.hasNext()) { 891 930 T o = i.next(); 892 if (o != removeme) 931 if (o != removeme) { 893 932 continue; 933 } 894 934 i.remove(); 895 935 ret = true; 896 936 break; 897 937 } 898 if (debug) 938 if (debug) { 899 939 out("qb slow remove result: " + ret); 940 } 900 941 return ret; 901 942 } … … 906 947 */ 907 948 QBLevel bucket = root.find_exact(o); 908 if (o instanceof Way) 949 if (o instanceof Way) { 909 950 way_bbox_cache.remove(o); 951 } 910 952 /* 911 953 * That may fail because the object was … … 916 958 return remove_slow(o); 917 959 boolean ret = bucket.remove_content(o); 918 if (debug) 960 if (debug) { 919 961 out("qb remove result: " + ret); 962 } 920 963 return ret; 921 964 } … … 932 975 { 933 976 ArrayList<T> a = new ArrayList<T>(); 934 for (T n : this) 977 for (T n : this) { 935 978 a.add(n); 936 if (debug) 937 out("returning array list with size: " + a.size()); 979 } 980 if (debug) { 981 out("returning array list with size: " + a.size()); 982 } 938 983 return a; 939 984 } … … 958 1003 QBLevel next = q.nextContentNode(); 959 1004 //if (consistency_testing && (orig == next)) 960 if (orig == next) 1005 if (orig == next) { 961 1006 abort("got same leaf back leaf: " + q.isLeaf()); 1007 } 962 1008 return next; 963 1009 } 964 1010 public QuadBucketIterator(QuadBuckets<T> qb) 965 1011 { 966 if (debug) 1012 if (debug) { 967 1013 out(this + " is a new iterator qb: " + qb + " size: " + qb.size()); 968 if (qb.root.isLeaf() || qb.root.hasContent()) 1014 } 1015 if (qb.root.isLeaf() || qb.root.hasContent()) { 969 1016 current_node = qb.root; 970 else1017 } else { 971 1018 current_node = next_content_node(qb.root); 972 if (debug) 1019 } 1020 if (debug) { 973 1021 out("\titerator first leaf: " + current_node); 1022 } 974 1023 iterated_over = 0; 975 1024 } … … 977 1026 { 978 1027 if (this.peek() == null) { 979 if (debug) 980 out(this + " no hasNext(), but iterated over so far: " + iterated_over); 1028 if (debug) { 1029 out(this + " no hasNext(), but iterated over so far: " + iterated_over); 1030 } 981 1031 return false; 982 1032 } … … 986 1036 { 987 1037 if (current_node == null) { 988 if (debug) 1038 if (debug) { 989 1039 out("null current leaf, nowhere to go"); 1040 } 990 1041 return null; 991 1042 } 992 1043 while((current_node.content == null) || 993 (content_index >= current_node.content.size())) {994 if (debug) 1044 (content_index >= current_node.content.size())) { 1045 if (debug) { 995 1046 out("moving to next leaf"); 1047 } 996 1048 content_index = 0; 997 1049 current_node = next_content_node(current_node); 998 if (current_node == null) 1050 if (current_node == null) { 999 1051 break; 1052 } 1000 1053 } 1001 1054 if (current_node == null || current_node.content == null) { 1002 if (debug) 1055 if (debug) { 1003 1056 out("late nowhere to go " + current_node); 1057 } 1004 1058 return null; 1005 1059 } … … 1010 1064 T ret = peek(); 1011 1065 content_index++; 1012 if (debug) 1066 if (debug) { 1013 1067 out("iteration["+iterated_over+"] " + content_index + " leaf: " + current_node); 1068 } 1014 1069 iterated_over++; 1015 1070 if (ret == null) { 1016 if (debug) 1071 if (debug) { 1017 1072 out(this + " no next node, but iterated over so far: " + iterated_over); 1073 } 1018 1074 } 1019 1075 return ret; … … 1038 1094 // This can certainly by optimized 1039 1095 int ret = root.size(); 1040 if (debug) 1096 if (debug) { 1041 1097 out(this + " QuadBuckets size: " + ret); 1098 } 1042 1099 return ret; 1043 1100 } … … 1061 1118 { 1062 1119 BBox bbox = new BBox(point.lon() - radius, point.lat() - radius, 1063 1064 if (debug) 1120 point.lon() + radius, point.lat() + radius); 1121 if (debug) { 1065 1122 out("search bbox before sanity: " + bbox); 1123 } 1066 1124 bbox.sanity(); 1067 if (debug) 1125 if (debug) { 1068 1126 out("search bbox after sanity: " + bbox); 1127 } 1069 1128 return bbox; 1070 1129 } … … 1101 1160 boolean cache_searches = true; 1102 1161 if (cache_searches) { 1103 if (search_cache == null) 1162 if (search_cache == null) { 1104 1163 search_cache = root; 1164 } 1105 1165 // Walk back up the tree when the last 1106 1166 // search spot can not cover the current 1107 1167 // search 1108 1168 while (!search_cache.bbox().bounds(search_bbox)) { 1109 if (debug) 1169 if (debug) { 1110 1170 out("bbox: " + search_bbox); 1171 } 1111 1172 if (debug) { 1112 1173 out("search_cache: " + search_cache + " level: " + search_cache.level); … … 1114 1175 } 1115 1176 search_cache = search_cache.parent; 1116 if (debug) 1177 if (debug) { 1117 1178 out("new search_cache: " + search_cache); 1179 } 1118 1180 } 1119 1181 } else { … … 1121 1183 } 1122 1184 ret = search_cache.search(search_bbox); 1123 if (ret == null) 1185 if (ret == null) { 1124 1186 ret = new ArrayList<T>(); 1187 } 1125 1188 // A way that spans this bucket may be stored in one 1126 1189 // of the nodes which is a parent of the search cache … … 1128 1191 while (tmp != null) { 1129 1192 List<T> content_result = tmp.search_contents(search_bbox); 1130 if (content_result != null) 1193 if (content_result != null) { 1131 1194 ret.addAll(content_result); 1195 } 1132 1196 tmp = tmp.parent; 1133 1197 } 1134 1198 if (ret == null || ret.size() == 0) 1135 1199 return Collections.emptyList(); 1136 if (debug) 1200 if (debug) { 1137 1201 out("search of QuadBuckets for " + search_bbox + " ret len: " + ret.size()); 1202 } 1138 1203 return ret; 1139 1204 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r2381 r2388 98 98 */ 99 99 protected <P extends OsmPrimitive> void mergePrimitive(P other, 100 Collection<P> myPrimitives, Collection<P> otherPrimitives, 101 HashMap<Long, P> primitivesWithDefinedIds) { 100 DataSet myDataset, Collection<P> myPrimitives, HashMap<Long, P> primitivesWithDefinedIds) { 102 101 103 102 if (!other.isNew() ) { … … 105 104 // defined id 106 105 // 107 if (mergeById( myPrimitives,primitivesWithDefinedIds, other))106 if (mergeById(primitivesWithDefinedIds, other)) 108 107 return; 109 108 } else { … … 136 135 // my dataset. Just add other to my dataset. 137 136 // 138 my Primitives.add(other);137 myDataset.addPrimitive(other); 139 138 } 140 139 141 140 public void visit(Node other) { 142 mergePrimitive(other, myDataSet .nodes, theirDataSet.nodes, nodeshash);141 mergePrimitive(other, myDataSet, myDataSet.getNodes(), nodeshash); 143 142 } 144 143 145 144 public void visit(Way other) { 146 145 fixWay(other); 147 mergePrimitive(other, myDataSet .ways, theirDataSet.ways, wayshash);146 mergePrimitive(other, myDataSet, myDataSet.getWays(), wayshash); 148 147 } 149 148 150 149 public void visit(Relation other) { 151 150 fixRelation(other); 152 mergePrimitive(other, myDataSet .relations, theirDataSet.relations, relshash);151 mergePrimitive(other, myDataSet, myDataSet.getRelations(), relshash); 153 152 } 154 153 … … 230 229 * Tries to merge a primitive <code>other</code> into an existing primitive with the same id. 231 230 * 232 * @param myPrimitives the complete set of my primitives (potential merge targets)233 231 * @param myPrimitivesWithDefinedIds the map of primitives (potential merge targets) with an id <> 0, for faster lookup 234 232 * by id. Key is the id, value the primitive with the given value. myPrimitives.valueSet() is a … … 237 235 * @return true, if this method was able to merge <code>other</code> with an existing node; false, otherwise 238 236 */ 239 private <P extends OsmPrimitive> boolean mergeById( 240 Collection<P> myPrimitives, HashMap<Long, P> myPrimitivesWithDefinedIds, P other) { 237 private <P extends OsmPrimitive> boolean mergeById(HashMap<Long, P> myPrimitivesWithDefinedIds, P other) { 241 238 242 239 // merge other into an existing primitive with the same id, if possible -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r2386 r2388 52 52 import org.openstreetmap.josm.data.osm.Node; 53 53 import org.openstreetmap.josm.data.osm.OsmPrimitive; 54 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;55 54 import org.openstreetmap.josm.data.osm.Relation; 56 55 import org.openstreetmap.josm.data.osm.Way; … … 458 457 // if uploaded, clean the modified flags as well 459 458 final Set<OsmPrimitive> processedSet = new HashSet<OsmPrimitive>(processed); 460 for (final Iterator<Node> it = data.nodes.iterator(); it.hasNext();) { 459 data.clenupDeletedPrimitives(); 460 for (final Iterator<Node> it = data.getNodes().iterator(); it.hasNext();) { 461 461 cleanIterator(it, processedSet); 462 462 } 463 for (final Iterator<Way> it = data. ways.iterator(); it.hasNext();) {463 for (final Iterator<Way> it = data.getWays().iterator(); it.hasNext();) { 464 464 cleanIterator(it, processedSet); 465 465 } 466 for (final Iterator<Relation> it = data. relations.iterator(); it.hasNext();) {466 for (final Iterator<Relation> it = data.getRelations().iterator(); it.hasNext();) { 467 467 cleanIterator(it, processedSet); 468 468 } … … 482 482 return; 483 483 osm.setModified(false); 484 if (osm.isDeleted()) {485 it.remove();486 }487 484 } 488 485 … … 507 504 508 505 String nodeText = trn("{0} node", "{0} nodes", counter.nodes, counter.nodes); 509 if (counter.deletedNodes > 0) 506 if (counter.deletedNodes > 0) { 510 507 nodeText += " ("+trn("{0} deleted", "{0} deleted", counter.deletedNodes, counter.deletedNodes)+")"; 508 } 511 509 512 510 String wayText = trn("{0} way", "{0} ways", counter.ways, counter.ways); 513 if (counter.deletedWays > 0) 511 if (counter.deletedWays > 0) { 514 512 wayText += " ("+trn("{0} deleted", "{0} deleted", counter.deletedWays, counter.deletedWays)+")"; 513 } 515 514 516 515 String relationText = trn("{0} relation", "{0} relations", counter.relations, counter.relations); 517 if (counter.deletedRelations > 0) 516 if (counter.deletedRelations > 0) { 518 517 relationText += " ("+trn("{0} deleted", "{0} deleted", counter.deletedRelations, counter.deletedRelations)+")"; 518 } 519 519 520 520 p.add(new JLabel(tr("{0} consists of:", getName())), GBC.eol()); -
trunk/test/functional/org/openstreetmap/josm/io/MultiFetchServerObjectReaderTest.java
r2381 r2388 15 15 import java.text.MessageFormat; 16 16 import java.util.ArrayList; 17 import java.util.Iterator;18 17 import java.util.Properties; 19 18 import java.util.logging.Level; … … 241 240 public void testMultiGet10Nodes() throws OsmTransferException { 242 241 MultiFetchServerObjectReader reader = new MultiFetchServerObjectReader(); 243 ArrayList<Node> nodes = new ArrayList<Node>(ds. nodes);242 ArrayList<Node> nodes = new ArrayList<Node>(ds.getNodes()); 244 243 for (int i =0; i< 10; i++) { 245 244 reader.append(nodes.get(i)); … … 247 246 DataSet out = reader.parseOsm(NullProgressMonitor.INSTANCE); 248 247 assertEquals(10, out.getNodes().size()); 249 Iterator<Node> it = out.nodes.iterator(); 250 while(it.hasNext()) { 251 Node n1 = it.next(); 248 for (Node n1:out.getNodes()) { 252 249 Node n2 = (Node)ds.getPrimitiveById(n1.getId(), OsmPrimitiveType.NODE); 253 250 assertNotNull(n2); … … 302 299 DataSet out = reader.parseOsm(NullProgressMonitor.INSTANCE); 303 300 assertEquals(812, out.getNodes().size()); 304 Iterator<Node> it = out.nodes.iterator(); 305 while(it.hasNext()) { 306 Node n1 = it.next(); 301 for (Node n1:out.getNodes()) { 307 302 Node n2 = (Node)ds.getPrimitiveById(n1.getId(), OsmPrimitiveType.NODE); 308 303 assertNotNull(n2); -
trunk/test/unit/org/openstreetmap/josm/data/osm/visitor/MergeSourceBuildingVisitorTest.java
r2381 r2388 332 332 RelationMember m = new RelationMember("node-20", lookupByName(hull.getNodes(), "n20")); 333 333 assertTrue(r.getMembers().contains(m)); 334 m = new RelationMember("way-30", lookupByName(hull. ways, "w30"));335 assertTrue(r.getMembers().contains(m)); 336 m = new RelationMember("relation-40", lookupByName(hull. relations, "r40"));334 m = new RelationMember("way-30", lookupByName(hull.getWays(), "w30")); 335 assertTrue(r.getMembers().contains(m)); 336 m = new RelationMember("relation-40", lookupByName(hull.getRelations(), "r40")); 337 337 assertTrue(r.getMembers().contains(m)); 338 338 }
Note:
See TracChangeset
for help on using the changeset viewer.