Changeset 2388 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-11-02T21:04:32+01:00 (14 years ago)
Author:
jttt
Message:

Replace Dataset.nodes with getNodes(), etc

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2381 r2388  
    1717
    1818import org.openstreetmap.josm.data.SelectionChangedListener;
     19import org.openstreetmap.josm.data.osm.QuadBuckets.BBox;
    1920
    2021/**
     
    6566    }
    6667
     68    public List<Node> searchNodes(BBox bbox) {
     69        return nodes.search(bbox);
     70    }
     71
    6772    /**
    6873     * All ways (Streets etc.) in the DataSet.
     
    7681    public Collection<Way> getWays() {
    7782        return Collections.unmodifiableCollection(ways);
     83    }
     84
     85    public List<Way> searchWays(BBox bbox) {
     86        return ways.search(bbox);
    7887    }
    7988
     
    438447        DataSet ds = new DataSet();
    439448        for (Node n : nodes) {
    440             ds.nodes.add(new Node(n));
     449            ds.addPrimitive(new Node(n));
    441450        }
    442451        for (Way w : ways) {
    443             ds.ways.add(new Way(w));
     452            ds.addPrimitive(new Way(w));
    444453        }
    445454        for (Relation e : relations) {
    446             ds.relations.add(new Relation(e));
     455            ds.addPrimitive(new Relation(e));
    447456        }
    448457        for (DataSource source : dataSources) {
     
    667676        return ret;
    668677    }
     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    }
    669705}
  • trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java

    r2380 r2388  
    44import java.util.Collection;
    55import java.util.Collections;
    6 import java.util.Set;
    7 import java.util.SortedMap;
    8 import java.util.TreeMap;
     6import java.util.HashMap;
     7import java.util.Iterator;
     8import java.util.LinkedList;
     9import java.util.List;
    910
    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 
     11import org.openstreetmap.josm.data.coor.LatLon;
    3312import org.openstreetmap.josm.data.coor.QuadTiling;
    34 import org.openstreetmap.josm.data.coor.EastNorth;
    35 import org.openstreetmap.josm.data.coor.LatLon;
    3613
    3714
     
    6542        long now = System.currentTimeMillis();
    6643        if ((now - last_out < 300) &&
    67             ((i+1) < total))
     44                ((i+1) < total))
    6845            return;
    6946        last_out = now;
     
    8259    public static int TILES_PER_LEVEL = 1<<TILES_PER_LEVEL_SHIFT;
    8360    // Maybe this should just be a Rectangle??
    84     class BBox
     61    public static class BBox
    8562    {
    8663        private double xmin = Double.POSITIVE_INFINITY;
     
    9067        void sanity()
    9168        {
    92             if (xmin < -180.0)
     69            if (xmin < -180.0) {
    9370                xmin = -180.0;
    94             if (xmax >  180.0)
     71            }
     72            if (xmax >  180.0) {
    9573                xmax =  180.0;
    96             if (ymin <  -90.0)
     74            }
     75            if (ymin <  -90.0) {
    9776                ymin =  -90.0;
    98             if (ymax >   90.0)
     77            }
     78            if (ymax >   90.0) {
    9979                ymax =   90.0;
     80            }
    10081            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)) {
    10485                out("bad BBox: " + this);
    10586                Object o = null;
     
    10788            }
    10889        }
     90        @Override
    10991        public String toString()
    11092        {
    11193            return "[ x: " + xmin + " -> " + xmax +
    112                    ", y: " + ymin + " -> " + ymax + " ]";
     94            ", y: " + ymin + " -> " + ymax + " ]";
    11395        }
    11496        double min(double a, double b)
     
    149131            for (Node n : w.getNodes()) {
    150132                LatLon coor = n.getCoor();
    151                 if (coor == null)
     133                if (coor == null) {
    152134                    continue;
     135                }
    153136                add(coor);
    154137            }
     
    166149        {
    167150            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))
    171154                return false;
    172155            return true;
     
    175158        {
    176159            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()))
    180163                return true;
    181164            return false;
     
    223206    BBox way_bbox(Way w)
    224207    {
    225         if (way_bbox_cache.size() > 100)
     208        if (way_bbox_cache.size() > 100) {
    226209            way_bbox_cache.clear();
     210        }
    227211        BBox b = way_bbox_cache.get(w);
    228212        if (b == null) {
     
    242226        public List<T> content;
    243227        public QBLevel children[];
     228        @Override
    244229        public String toString()
    245230        {
     
    263248        {
    264249            boolean ret = this.content.remove(o);
    265             if (this.content.size() == 0)
     250            if (this.content.size() == 0) {
    266251                this.content = null;
     252            }
    267253            return ret;
    268254        }
     
    282268        int get_index(T o, int level)
    283269        {
    284             if (debug)
     270            if (debug) {
    285271                out("getting index for " + o + " at level: " + level);
     272            }
    286273            if (o instanceof Node) {
    287274                Node n = (Node)o;
     
    296283                //for (Node n : w.getNodes()) {
    297284                for (LatLon c : way_bbox(w).points()) {
    298                 //    LatLon c = n.getCoor();
    299                     if (debug)
     285                    //    LatLon c = n.getCoor();
     286                    if (debug) {
    300287                        out("getting index for point: " + c);
     288                    }
    301289                    if (index == -1) {
    302290                        index = QuadTiling.index(c, level);
    303                         if (debug)
     291                        if (debug) {
    304292                            out("set initial way index to: " + index);
     293                        }
    305294                        continue;
    306295                    }
    307296                    int node_index = QuadTiling.index(c, level);
    308                     if (debug)
     297                    if (debug) {
    309298                        out("other node way index: " + node_index);
     299                    }
    310300                    if (node_index != index) {
    311301                        // This happens at level 0 sometimes when a way has no
     
    315305                                    + node_index + "/" + index + " at level: " + level + "    ");
    316306                            out("node count: " + w.getNodes().size());
    317                             for (LatLon c2 : way_bbox(w).points())
     307                            for (LatLon c2 : way_bbox(w).points()) {
    318308                                out("points: " + c2);
     309                            }
    319310                        }
    320311                        return -1;
     
    328319        void split()
    329320        {
    330             if (debug)
     321            if (debug) {
    331322                out("splitting "+this.bbox()+" level "+level+" with "
    332323                        + content.size() + " entries (my dimensions: "
    333324                        + this.bbox.width()+", "+this.bbox.height()+")");
     325            }
    334326            if (children != null) {
    335327                abort("overwrote children");
     
    349341                    continue;
    350342                }
    351                 if (children[new_index] == null)
     343                if (children[new_index] == null) {
    352344                    children[new_index] = new QBLevel(this, new_index);
     345                }
    353346                QBLevel child = children[new_index];
    354                 if (debug)
     347                if (debug) {
    355348                    out("putting "+o+"(q:"+quads(o)+") into ["+new_index+"] " + child.bbox());
     349                }
    356350                child.add(o);
    357351            }
     
    360354        {
    361355            boolean ret = false;
    362             if (content == null)
     356            if (content == null) {
    363357                content = new ArrayList<T>();
     358            }
    364359            ret = content.add(o);
    365             if (debug && !this.isLeaf())
     360            if (debug && !this.isLeaf()) {
    366361                pout("added "+o.getClass().getName()+" to non-leaf with size: " + content.size());
     362            }
    367363            return ret;
    368364        }
     
    372368            add_content(o);
    373369            if (content.size() > MAX_OBJECTS_PER_LEVEL) {
    374                 if (debug)
     370                if (debug) {
    375371                    out("["+level+"] deciding to split");
     372                }
    376373                if (level >= NR_LEVELS-1) {
    377374                    out("can not split, but too deep: " + level + " size: " + content.size());
     
    379376                }
    380377                int before_size = -1;
    381                 if (consistency_testing)
     378                if (consistency_testing) {
    382379                    before_size = this.size();
     380                }
    383381                this.split();
    384382                if (consistency_testing) {
     
    410408        {
    411409            String size = "null";
    412             if (content != null)
     410            if (content != null) {
    413411                size = ""+content.size();
    414             if (debug)
     412            }
     413            if (debug) {
    415414                out("searching contents (size: "+size+") for " + search_bbox);
     415            }
    416416            /*
    417417             * It is possible that this was created in a split
     
    428428            List<T> ret = new LinkedList<T>();
    429429            for (T o : content) {
    430                 if (matches(o, search_bbox))
     430                if (matches(o, search_bbox)) {
    431431                    ret.add(o);
    432             }
    433             if (debug)
     432                }
     433            }
     434            if (debug) {
    434435                out("done searching quad " + Long.toHexString(this.quad));
     436            }
    435437            return ret;
    436438        }
     
    457459                int nr = __nr-1;
    458460                if (sibling == null) {
    459                     if (debug)
     461                    if (debug) {
    460462                        out("[" + this.level + "] null child nr: " + nr);
     463                    }
    461464                    continue;
    462465                }
     
    464467                // after us.
    465468                if (sibling == this) {
    466                     if (debug)
     469                    if (debug) {
    467470                        out("[" + this.level + "] I was child nr: " + nr);
     471                    }
    468472                    found_me = true;
    469473                    continue;
    470474                }
    471475                if (found_me) {
    472                     if (debug)
     476                    if (debug) {
    473477                        out("[" + this.level + "] next sibling was child nr: " + nr);
     478                    }
    474479                    return sibling;
    475480                }
    476                 if (debug)
     481                if (debug) {
    477482                    out("[" + this.level + "] nr: " + nr + " is before me, ignoring...");
     483                }
    478484            }
    479485            return null;
     
    494500                // a leaf or branch.
    495501                while (sibling == null) {
    496                     if (debug)
     502                    if (debug) {
    497503                        out("no siblings at level["+next.level+"], moving to parent");
     504                    }
    498505                    next = next.parent;
    499                     if (next == null)
     506                    if (next == null) {
    500507                        break;
     508                    }
    501509                    sibling = next.next_sibling();
    502510                }
     
    511519            // and find the first leaf
    512520            while (!next.isLeaf()) {
    513                 if (next.hasContent() && next != this)
     521                if (next.hasContent() && next != this) {
    514522                    break;
    515                 if (debug)
     523                }
     524                if (debug) {
    516525                    out("["+next.level+"] next node ("+next+") is a branch (content: "+next.hasContent()+"), moving down...");
     526                }
    517527                for (QBLevel child : next.children) {
    518                     if (child == null)
     528                    if (child == null) {
    519529                        continue;
     530                    }
    520531                    next = child;
    521532                    break;
     
    533544        {
    534545            if (content == null) {
    535                 if (debug)
     546                if (debug) {
    536547                    out("["+level+"] leaf size: null content, children? " + children);
     548                }
    537549                return 0;
    538550            }
    539             if (debug)
     551            if (debug) {
    540552                out("["+level+"] leaf size: " + content.size());
     553            }
    541554            return content.size();
    542555        }
     
    545558            int ret = 0;
    546559            for (QBLevel l : children) {
    547                 if (l == null)
     560                if (l == null) {
    548561                    continue;
     562                }
    549563                ret += l.size();
    550564            }
    551             if (content != null)
     565            if (content != null) {
    552566                ret += content.size();
    553             if (debug)
     567            }
     568            if (debug) {
    554569                out("["+level+"] branch size: " + ret);
     570            }
    555571            return ret;
    556572        }
     
    575591                return ret;
    576592            for (QBLevel l : children) {
    577                 if (l == null)
     593                if (l == null) {
    578594                    continue;
     595                }
    579596                ret = l.find_exact(n);
    580                 if (ret != null)
     597                if (ret != null) {
    581598                    break;
     599                }
    582600            }
    583601            return ret;
     
    593611                }
    594612            }
    595             if (isLeaf())
     613            if (isLeaf()) {
    596614                add_to_leaf(n);
    597             else
     615            } else {
    598616                add_to_branch(n);
     617            }
    599618            return true;
    600619        }
     
    603622            int index = get_index(n, level);
    604623            if (index == -1) {
    605                 if (debug)
     624                if (debug) {
    606625                    out("unable to get index for " + n + "at level: " + level + ", adding content to branch: " + this);
     626                }
    607627                this.add_content(n);
    608628                return this;
     
    610630            if (debug) {
    611631                out("[" + level + "]: " + n +
    612                     " index " + index + " levelquad:" + this.quads() + " level bbox:" + this.bbox());
     632                        " index " + index + " levelquad:" + this.quads() + " level bbox:" + this.bbox());
    613633                out("   put in child["+index+"]");
    614634            }
    615             if (children[index] == null)
     635            if (children[index] == null) {
    616636                children[index] = new QBLevel(this, index);
     637            }
    617638            children[index].add(n);
    618639            return this;
     
    621642        {
    622643            List<T> ret = null;
    623             if (debug)
     644            if (debug) {
    624645                System.out.print("[" + level + "] qb bbox: " + this.bbox() + " ");
     646            }
    625647            if (!this.bbox().intersects(search_bbox)) {
    626648                if (debug) {
     
    630652                return ret;
    631653            }
    632             if (this.hasContent())
     654            if (this.hasContent()) {
    633655                ret = this.search_contents(search_bbox);
    634             if (this.isLeaf()) {
     656            }
     657            if (this.isLeaf())
    635658                return ret;
    636             }
    637659            //if (this.hasContent())
    638660            //    abort("branch had stuff");
    639             if (debug)
     661            if (debug) {
    640662                out("hit " + this.quads());
     663            }
    641664
    642             if (debug)
     665            if (debug) {
    643666                out("[" + level + "] not leaf, moving down");
     667            }
    644668            for (int i = 0; i < children.length; i++) {
    645669                QBLevel q = children[i];
    646                 if (debug)
     670                if (debug) {
    647671                    out("child["+i+"]: " + q);
    648                 if (q == null)
     672                }
     673                if (q == null) {
    649674                    continue;
    650                 if (debug)
     675                }
     676                if (debug) {
    651677                    System.out.print(i+": ");
     678                }
    652679                List<T> coors = q.search(search_bbox);
    653                 if (coors == null)
     680                if (coors == null) {
    654681                    continue;
    655                 if (ret == null)
     682                }
     683                if (ret == null) {
    656684                    ret = coors;
    657                 else
     685                } else {
    658686                    ret.addAll(coors);
     687                }
    659688                if (q.bbox().bounds(search_bbox)) {
    660689                    search_cache = q;
     
    663692                    // what we were looking for.
    664693                    if (coors.size() > 0 ) {
    665                         if (debug)
     694                        if (debug) {
    666695                            out("break early");
     696                        }
    667697                        break;
    668698                    }
     
    677707        public void init(QBLevel parent)
    678708        {
    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;
    685716        }
    686717        int index_of(QBLevel find_this)
     
    708739            long this_quadpart = mult * (parent_index << shift);
    709740            this.quad = parent.quad | this_quadpart;
    710             if (debug)
     741            if (debug) {
    711742                out("new level["+this.level+"] bbox["+parent_index+"]: " + this.bbox()
    712743                        + " coor: " + this.coor()
    713744                        + " quadpart: " + Long.toHexString(this_quadpart)
    714745                        + " quad: " + Long.toHexString(this.quad));
     746            }
    715747        }
    716748        /*
     
    779811    public boolean add(T n)
    780812    {
    781         if (debug)
     813        if (debug) {
    782814            out("QuadBuckets() add: " + n + " size now: " + this.size());
     815        }
    783816        int before_size = -1;
    784         if (consistency_testing)
     817        if (consistency_testing) {
    785818            before_size = root.size();
     819        }
    786820        boolean ret;
    787821        // A way with no nodes will have an infinitely large
    788822        // bounding box.  Just stash it in the root node.
    789         if (!n.isUsable())
     823        if (!n.isUsable()) {
    790824            ret = root.add_content(n);
    791         else
     825        } else {
    792826            ret = root.add(n);
     827        }
    793828        if (consistency_testing) {
    794829            int end_size = root.size();
    795             if (ret)
     830            if (ret) {
    796831                end_size--;
    797             if (before_size != end_size)
     832            }
     833            if (before_size != end_size) {
    798834                abort("size inconsistency before add: " + before_size + " after: " + end_size);
    799         }
    800         if (debug)
     835            }
     836        }
     837        if (debug) {
    801838            out("QuadBuckets() add: " + n + " size after: " + this.size());
     839        }
    802840        return ret;
    803841    }
     
    820858    {
    821859        for (T o : this) {
    822             if (objects.contains(o))
     860            if (objects.contains(o)) {
    823861                continue;
     862            }
    824863            if (!this.remove(o))
    825864                return false;
     
    890929        while (i.hasNext()) {
    891930            T o = i.next();
    892             if (o != removeme)
     931            if (o != removeme) {
    893932                continue;
     933            }
    894934            i.remove();
    895935            ret = true;
    896936            break;
    897937        }
    898         if (debug)
     938        if (debug) {
    899939            out("qb slow remove result: " + ret);
     940        }
    900941        return ret;
    901942    }
     
    906947         */
    907948        QBLevel bucket = root.find_exact(o);
    908         if (o instanceof Way)
     949        if (o instanceof Way) {
    909950            way_bbox_cache.remove(o);
     951        }
    910952        /*
    911953         * That may fail because the object was
     
    916958            return remove_slow(o);
    917959        boolean ret = bucket.remove_content(o);
    918         if (debug)
     960        if (debug) {
    919961            out("qb remove result: " + ret);
     962        }
    920963        return ret;
    921964    }
     
    932975    {
    933976        ArrayList<T> a = new ArrayList<T>();
    934         for (T n : this)
     977        for (T n : this) {
    935978            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        }
    938983        return a;
    939984    }
     
    9581003            QBLevel next = q.nextContentNode();
    9591004            //if (consistency_testing && (orig == next))
    960             if (orig == next)
     1005            if (orig == next) {
    9611006                abort("got same leaf back leaf: " + q.isLeaf());
     1007            }
    9621008            return next;
    9631009        }
    9641010        public QuadBucketIterator(QuadBuckets<T> qb)
    9651011        {
    966             if (debug)
     1012            if (debug) {
    9671013                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()) {
    9691016                current_node = qb.root;
    970             else
     1017            } else {
    9711018                current_node = next_content_node(qb.root);
    972             if (debug)
     1019            }
     1020            if (debug) {
    9731021                out("\titerator first leaf: " + current_node);
     1022            }
    9741023            iterated_over = 0;
    9751024        }
     
    9771026        {
    9781027            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                }
    9811031                return false;
    9821032            }
     
    9861036        {
    9871037            if (current_node == null) {
    988                 if (debug)
     1038                if (debug) {
    9891039                    out("null current leaf, nowhere to go");
     1040                }
    9901041                return null;
    9911042            }
    9921043            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) {
    9951046                    out("moving to next leaf");
     1047                }
    9961048                content_index = 0;
    9971049                current_node = next_content_node(current_node);
    998                 if (current_node == null)
     1050                if (current_node == null) {
    9991051                    break;
     1052                }
    10001053            }
    10011054            if (current_node == null || current_node.content == null) {
    1002                 if (debug)
     1055                if (debug) {
    10031056                    out("late nowhere to go " + current_node);
     1057                }
    10041058                return null;
    10051059            }
     
    10101064            T ret = peek();
    10111065            content_index++;
    1012             if (debug)
     1066            if (debug) {
    10131067                out("iteration["+iterated_over+"] " + content_index + " leaf: " + current_node);
     1068            }
    10141069            iterated_over++;
    10151070            if (ret == null) {
    1016                 if (debug)
     1071                if (debug) {
    10171072                    out(this + " no next node, but iterated over so far: " + iterated_over);
     1073                }
    10181074            }
    10191075            return ret;
     
    10381094        // This can certainly by optimized
    10391095        int ret = root.size();
    1040         if (debug)
     1096        if (debug) {
    10411097            out(this + " QuadBuckets size: " + ret);
     1098        }
    10421099        return ret;
    10431100    }
     
    10611118    {
    10621119        BBox bbox = new BBox(point.lon() - radius, point.lat() - radius,
    1063                              point.lon() + radius, point.lat() + radius);
    1064         if (debug)
     1120                point.lon() + radius, point.lat() + radius);
     1121        if (debug) {
    10651122            out("search bbox before sanity: " +  bbox);
     1123        }
    10661124        bbox.sanity();
    1067         if (debug)
     1125        if (debug) {
    10681126            out("search bbox after sanity: " +  bbox);
     1127        }
    10691128        return bbox;
    10701129    }
     
    11011160        boolean cache_searches = true;
    11021161        if (cache_searches) {
    1103             if (search_cache == null)
     1162            if (search_cache == null) {
    11041163                search_cache = root;
     1164            }
    11051165            // Walk back up the tree when the last
    11061166            // search spot can not cover the current
    11071167            // search
    11081168            while (!search_cache.bbox().bounds(search_bbox)) {
    1109                 if (debug)
     1169                if (debug) {
    11101170                    out("bbox: " + search_bbox);
     1171                }
    11111172                if (debug) {
    11121173                    out("search_cache: " + search_cache + " level: " + search_cache.level);
     
    11141175                }
    11151176                search_cache = search_cache.parent;
    1116                 if (debug)
     1177                if (debug) {
    11171178                    out("new search_cache: " + search_cache);
     1179                }
    11181180            }
    11191181        } else {
     
    11211183        }
    11221184        ret = search_cache.search(search_bbox);
    1123         if (ret == null)
     1185        if (ret == null) {
    11241186            ret = new ArrayList<T>();
     1187        }
    11251188        // A way that spans this bucket may be stored in one
    11261189        // of the nodes which is a parent of the search cache
     
    11281191        while (tmp != null) {
    11291192            List<T> content_result = tmp.search_contents(search_bbox);
    1130             if (content_result != null)
     1193            if (content_result != null) {
    11311194                ret.addAll(content_result);
     1195            }
    11321196            tmp = tmp.parent;
    11331197        }
    11341198        if (ret == null || ret.size() == 0)
    11351199            return Collections.emptyList();
    1136         if (debug)
     1200        if (debug) {
    11371201            out("search of QuadBuckets for " + search_bbox + " ret len: " + ret.size());
     1202        }
    11381203        return ret;
    11391204    }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r2381 r2388  
    9898     */
    9999    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) {
    102101
    103102        if (!other.isNew() ) {
     
    105104            // defined id
    106105            //
    107             if (mergeById(myPrimitives, primitivesWithDefinedIds, other))
     106            if (mergeById(primitivesWithDefinedIds, other))
    108107                return;
    109108        } else {
     
    136135        // my dataset. Just add other to my dataset.
    137136        //
    138         myPrimitives.add(other);
     137        myDataset.addPrimitive(other);
    139138    }
    140139
    141140    public void visit(Node other) {
    142         mergePrimitive(other, myDataSet.nodes, theirDataSet.nodes, nodeshash);
     141        mergePrimitive(other, myDataSet, myDataSet.getNodes(), nodeshash);
    143142    }
    144143
    145144    public void visit(Way other) {
    146145        fixWay(other);
    147         mergePrimitive(other, myDataSet.ways, theirDataSet.ways, wayshash);
     146        mergePrimitive(other, myDataSet, myDataSet.getWays(), wayshash);
    148147    }
    149148
    150149    public void visit(Relation other) {
    151150        fixRelation(other);
    152         mergePrimitive(other, myDataSet.relations, theirDataSet.relations, relshash);
     151        mergePrimitive(other, myDataSet, myDataSet.getRelations(), relshash);
    153152    }
    154153
     
    230229     * Tries to merge a primitive <code>other</code> into an existing primitive with the same id.
    231230     *
    232      * @param myPrimitives the complete set of my primitives (potential merge targets)
    233231     * @param myPrimitivesWithDefinedIds the map of primitives (potential merge targets) with an id <> 0, for faster lookup
    234232     *    by id. Key is the id, value the primitive with the given value. myPrimitives.valueSet() is a
     
    237235     * @return true, if this method was able to merge <code>other</code> with an existing node; false, otherwise
    238236     */
    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) {
    241238
    242239        // merge other into an existing primitive with the same id, if possible
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r2386 r2388  
    5252import org.openstreetmap.josm.data.osm.Node;
    5353import org.openstreetmap.josm.data.osm.OsmPrimitive;
    54 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    5554import org.openstreetmap.josm.data.osm.Relation;
    5655import org.openstreetmap.josm.data.osm.Way;
     
    458457        // if uploaded, clean the modified flags as well
    459458        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();) {
    461461            cleanIterator(it, processedSet);
    462462        }
    463         for (final Iterator<Way> it = data.ways.iterator(); it.hasNext();) {
     463        for (final Iterator<Way> it = data.getWays().iterator(); it.hasNext();) {
    464464            cleanIterator(it, processedSet);
    465465        }
    466         for (final Iterator<Relation> it = data.relations.iterator(); it.hasNext();) {
     466        for (final Iterator<Relation> it = data.getRelations().iterator(); it.hasNext();) {
    467467            cleanIterator(it, processedSet);
    468468        }
     
    482482            return;
    483483        osm.setModified(false);
    484         if (osm.isDeleted()) {
    485             it.remove();
    486         }
    487484    }
    488485
     
    507504
    508505        String nodeText = trn("{0} node", "{0} nodes", counter.nodes, counter.nodes);
    509         if (counter.deletedNodes > 0)
     506        if (counter.deletedNodes > 0) {
    510507            nodeText += " ("+trn("{0} deleted", "{0} deleted", counter.deletedNodes, counter.deletedNodes)+")";
     508        }
    511509
    512510        String wayText = trn("{0} way", "{0} ways", counter.ways, counter.ways);
    513         if (counter.deletedWays > 0)
     511        if (counter.deletedWays > 0) {
    514512            wayText += " ("+trn("{0} deleted", "{0} deleted", counter.deletedWays, counter.deletedWays)+")";
     513        }
    515514
    516515        String relationText = trn("{0} relation", "{0} relations", counter.relations, counter.relations);
    517         if (counter.deletedRelations > 0)
     516        if (counter.deletedRelations > 0) {
    518517            relationText += " ("+trn("{0} deleted", "{0} deleted", counter.deletedRelations, counter.deletedRelations)+")";
     518        }
    519519
    520520        p.add(new JLabel(tr("{0} consists of:", getName())), GBC.eol());
Note: See TracChangeset for help on using the changeset viewer.