Ignore:
Timestamp:
2010-08-29T14:55:25+02:00 (14 years ago)
Author:
jttt
Message:

cosmetics

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/PurgeCommand.java

    r3431 r3479  
    104104                    PrimitiveData empty;
    105105                    switch(osm.getType()) {
    106                         case NODE: empty = new NodeData(); break;
    107                         case WAY: empty = new WayData(); break;
    108                         case RELATION: empty = new RelationData(); break;
    109                         default: throw new AssertionError();
     106                    case NODE: empty = new NodeData(); break;
     107                    case WAY: empty = new WayData(); break;
     108                    case RELATION: empty = new RelationData(); break;
     109                    default: throw new AssertionError();
    110110                    }
    111111                    empty.setId(osm.getUniqueId());
     
    154154         */
    155155        outer:
    156         for (Iterator<OsmPrimitive> it = in.iterator(); it.hasNext();) {
    157             OsmPrimitive u = it.next();
    158             if (u instanceof Node) {
    159                 Node n = (Node) u;
    160                 for (OsmPrimitive ref : n.getReferrers()) {
    161                     if (ref instanceof Way && in.contains(ref))
    162                         continue outer;
    163                 }
    164                 it.remove();
    165                 out.add(n);
    166             }
    167         }
     156            for (Iterator<OsmPrimitive> it = in.iterator(); it.hasNext();) {
     157                OsmPrimitive u = it.next();
     158                if (u instanceof Node) {
     159                    Node n = (Node) u;
     160                    for (OsmPrimitive ref : n.getReferrers()) {
     161                        if (ref instanceof Way && in.contains(ref)) {
     162                            continue outer;
     163                        }
     164                    }
     165                    it.remove();
     166                    out.add(n);
     167                }
     168            }
    168169
    169170        /**
     
    171172         */
    172173        top:
    173         while (!in.isEmpty()) {
    174             for (Iterator<OsmPrimitive> it = in.iterator(); it.hasNext();) {
    175                 OsmPrimitive u = it.next();
    176                 if (u instanceof Way) {
    177                     Way w = (Way) u;
    178                     it.remove();
    179                     for (Node n : w.getNodes()) {
    180                         if (in.contains(n)) {
    181                             in.remove(n);
    182                             out.add(n);
     174            while (!in.isEmpty()) {
     175                for (Iterator<OsmPrimitive> it = in.iterator(); it.hasNext();) {
     176                    OsmPrimitive u = it.next();
     177                    if (u instanceof Way) {
     178                        Way w = (Way) u;
     179                        it.remove();
     180                        for (Node n : w.getNodes()) {
     181                            if (in.contains(n)) {
     182                                in.remove(n);
     183                                out.add(n);
     184                            }
    183185                        }
    184                     }
    185                     out.add(w);
    186                     continue top;
    187                 }
    188             }
    189             break; // no more ways left
    190         }
    191 
    192         /**
    193          * Rest are relations. Do topological sorting on a DAG where each
    194          * arrow points from child to parent. (Because it is faster to
    195          * loop over getReferrers() than getMembers().)
    196          */
    197         Set<Relation> inR = (Set) in;
    198         Set<Relation> childlessR = new HashSet<Relation>();
    199         List<Relation> outR = new ArrayList<Relation>(inR.size());
    200 
    201         HashMap<Relation, Integer> numChilds = new HashMap<Relation, Integer>();
    202 
    203         // calculate initial number of childs
    204         for (Relation r : inR) {
    205             numChilds.put(r, 0);
    206         }
    207         for (Relation r : inR) {
    208             for (OsmPrimitive parent : r.getReferrers()) {
    209                 if (!(parent instanceof Relation))
    210                     throw new AssertionError();
    211                 Integer i = numChilds.get((Relation)parent);
    212                 if (i != null) {
    213                     numChilds.put((Relation)parent, i+1);
    214                 }
    215             }
    216         }
    217         for (Relation r : inR) {
    218             if (numChilds.get(r).equals(0)) {
    219                 childlessR.add(r);
    220             }
    221         }
    222 
    223         while (!childlessR.isEmpty()) {
    224             // Identify one childless Relation and
    225             // let it virtually die. This makes other
    226             // relations childless.
    227             Iterator<Relation> it  = childlessR.iterator();
    228             Relation next = it.next();
    229             it.remove();
    230             outR.add(next);
    231 
    232             for (OsmPrimitive parentPrim : next.getReferrers()) {
    233                 Relation parent = (Relation) parentPrim;
    234                 Integer i = numChilds.get(parent);
    235                 if (i != null) {
    236                     numChilds.put(parent, i-1);
    237                     if (i-1 == 0) {
    238                         childlessR.add(parent);
    239                     }
    240                 }
    241             }
    242         }
    243 
    244         if (outR.size() != inR.size())
    245             throw new AssertionError("topo sort algorithm failed");
    246 
    247         out.addAll(outR);
    248 
    249         return out;
    250     }
    251    
     186                        out.add(w);
     187                        continue top;
     188                    }
     189                }
     190                break; // no more ways left
     191            }
     192
     193            /**
     194             * Rest are relations. Do topological sorting on a DAG where each
     195             * arrow points from child to parent. (Because it is faster to
     196             * loop over getReferrers() than getMembers().)
     197             */
     198            Set<Relation> inR = (Set) in;
     199            Set<Relation> childlessR = new HashSet<Relation>();
     200            List<Relation> outR = new ArrayList<Relation>(inR.size());
     201
     202            HashMap<Relation, Integer> numChilds = new HashMap<Relation, Integer>();
     203
     204            // calculate initial number of childs
     205            for (Relation r : inR) {
     206                numChilds.put(r, 0);
     207            }
     208            for (Relation r : inR) {
     209                for (OsmPrimitive parent : r.getReferrers()) {
     210                    if (!(parent instanceof Relation))
     211                        throw new AssertionError();
     212                    Integer i = numChilds.get(parent);
     213                    if (i != null) {
     214                        numChilds.put((Relation)parent, i+1);
     215                    }
     216                }
     217            }
     218            for (Relation r : inR) {
     219                if (numChilds.get(r).equals(0)) {
     220                    childlessR.add(r);
     221                }
     222            }
     223
     224            while (!childlessR.isEmpty()) {
     225                // Identify one childless Relation and
     226                // let it virtually die. This makes other
     227                // relations childless.
     228                Iterator<Relation> it  = childlessR.iterator();
     229                Relation next = it.next();
     230                it.remove();
     231                outR.add(next);
     232
     233                for (OsmPrimitive parentPrim : next.getReferrers()) {
     234                    Relation parent = (Relation) parentPrim;
     235                    Integer i = numChilds.get(parent);
     236                    if (i != null) {
     237                        numChilds.put(parent, i-1);
     238                        if (i-1 == 0) {
     239                            childlessR.add(parent);
     240                        }
     241                    }
     242                }
     243            }
     244
     245            if (outR.size() != inR.size())
     246                throw new AssertionError("topo sort algorithm failed");
     247
     248            out.addAll(outR);
     249
     250            return out;
     251    }
     252
    252253    @Override
    253254    public Object getDescription() {
Note: See TracChangeset for help on using the changeset viewer.