Changeset 3486 in josm
- Timestamp:
- 2010-08-29T16:20:19+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/PurgeCommand.java
r3479 r3486 191 191 } 192 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 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 251 } 252 252 -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r3481 r3486 949 949 setButtonIcons(new String[] {"ok.png", "cancel.png" }); 950 950 setContent(content); 951 setDefaultButton(1); 951 952 setupDialog(); 952 953 buttons.get(0).setEnabled(!disableApply); 953 954 buttons.get(0).setToolTipText(title); 954 getRootPane().setDefaultButton(buttons.get(0)); 955 setVisible(true); 955 showDialog(); 956 956 } 957 957 }
Note:
See TracChangeset
for help on using the changeset viewer.