- Timestamp:
- 2009-09-20T11:07:46+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
r2017 r2166 172 172 // if it is, delete it 173 173 CollectBackReferencesVisitor refs = new CollectBackReferencesVisitor(getCurrentDataSet()); 174 refs.initialize(); 174 175 refs.visit(n1); 175 if (refs. data.isEmpty() || ((refs.data.size() == 1) && (refs.data.contains(existingWay)))) {176 if (refs.getData().isEmpty() || ((refs.getData().size() == 1) && (refs.getData().contains(existingWay)))) { 176 177 cmds.add(new DeleteCommand(n1)); 177 178 } -
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r2145 r2166 182 182 searchText = (((Filter)s).inverted ? "-" : "") + "(" + searchText + ")"; 183 183 } 184 System.out.println(searchText);184 /*System.out.println(searchText);*/ 185 185 SearchCompiler.Match matcher = SearchCompiler.compile(searchText, s.caseSensitive, s.regexSearch); 186 186 foundMatches = 0; -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r2070 r2166 33 33 private String rxErrorMsg = marktr("The regex \"{0}\" had a parse error at offset {1}, full error:\n\n{2}"); 34 34 private PushbackTokenizer tokenizer; 35 private static CollectBackReferencesVisitor childBackRefs; 35 36 36 37 public SearchCompiler(boolean caseSensitive, boolean regexSearch, PushbackTokenizer tokenizer) { … … 38 39 this.regexSearch = regexSearch; 39 40 this.tokenizer = tokenizer; 41 childBackRefs = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet()); 40 42 } 41 43 … … 481 483 482 484 boolean isChild = false; 483 CollectBackReferencesVisitor backRefs = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet());484 osm.visit( backRefs);485 for (OsmPrimitive p : backRefs.data) {485 childBackRefs.initialize(); 486 osm.visit(childBackRefs); 487 for (OsmPrimitive p : childBackRefs.getData()) { 486 488 isChild |= parent.match(p); 487 489 } -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r2070 r2166 163 163 public static Command deleteWithReferences(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection, boolean simulate) { 164 164 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data); 165 v.initialize(); 165 166 for (OsmPrimitive osm : selection) { 166 167 osm.visit(v); 167 168 } 168 v. data.addAll(selection);169 if (v. data.isEmpty())169 v.getData().addAll(selection); 170 if (v.getData().isEmpty()) 170 171 return null; 171 if (!checkAndConfirmOutlyingDeletes(layer,v. data) && !simulate)172 if (!checkAndConfirmOutlyingDeletes(layer,v.getData()) && !simulate) 172 173 return null; 173 return new DeleteCommand(layer,v. data);174 return new DeleteCommand(layer,v.getData()); 174 175 } 175 176 … … 239 240 protected static Collection<Node> computeNodesToDelete(OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) { 240 241 Collection<Node> nodesToDelete = new HashSet<Node>(); 242 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data, false); 241 243 for (OsmPrimitive osm : primitivesToDelete) { 242 244 if (! (osm instanceof Way) ) { … … 247 249 continue; 248 250 } 249 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data, false);251 v.initialize(); 250 252 n.visit(v); 251 v. data.removeAll(primitivesToDelete);252 if (v. data.isEmpty()) {253 v.getData().removeAll(primitivesToDelete); 254 if (v.getData().isEmpty()) { 253 255 nodesToDelete.add(n); 254 256 } … … 297 299 return null; 298 300 301 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data, false); 299 302 for (OsmPrimitive osm : primitivesToDelete) { 300 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data, false);303 v.initialize(); 301 304 osm.visit(v); 302 for (OsmPrimitive ref : v. data) {305 for (OsmPrimitive ref : v.getData()) { 303 306 if (primitivesToDelete.contains(ref)) { 304 307 continue; … … 328 331 primitivesToDelete.add(w); 329 332 330 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data, false);333 v.initialize(); 331 334 w.visit(v); 332 for (OsmPrimitive ref : v. data) {335 for (OsmPrimitive ref : v.getData()) { 333 336 if (primitivesToDelete.contains(ref)) { 334 337 continue; -
trunk/src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java
r2070 r2166 4 4 import java.util.Collection; 5 5 import java.util.HashSet; 6 import java.util.HashMap; 7 import java.util.Map; 6 8 7 9 import org.openstreetmap.josm.data.osm.DataSet; … … 17 19 * Deleted objects are not collected. 18 20 * 19 * @author imi 21 * @author imi, Petr Dlouhý 20 22 */ 21 23 public class CollectBackReferencesVisitor extends AbstractVisitor { … … 24 26 private final boolean indirectRefs; 25 27 26 /** 27 * The result list of primitives stored here. 28 */ 29 public final Collection<OsmPrimitive> data = new HashSet<OsmPrimitive>(); 28 private Collection<OsmPrimitive> data = new HashSet<OsmPrimitive>(); 29 private Map<OsmPrimitive, Collection<OsmPrimitive>> lookupTable = new HashMap<OsmPrimitive, Collection<OsmPrimitive>>(); 30 30 31 31 32 32 /** 33 33 * Construct a back reference counter. 34 * has time complexity O(n) - so it is appropriate not to call it in cycle 34 35 * @param ds The dataset to operate on. 35 36 */ 36 37 public CollectBackReferencesVisitor(DataSet ds) { 37 this.ds = ds; 38 this.indirectRefs = true; 38 this(ds, true); 39 39 } 40 40 41 /** 42 * Construct a back reference counter. 43 * has time complexity O(n) - so it is appropriate not to call it in cycle 44 * @param ds The dataset to operate on. 45 * @param indirectRefs Make also indirect references? 46 */ 41 47 public CollectBackReferencesVisitor(DataSet ds, boolean indirectRefs) { 42 this.ds = ds; 43 this.indirectRefs = indirectRefs; 48 this.ds = ds; 49 this.indirectRefs = indirectRefs; 50 if(ds != null) 51 makeLookupTable(); 52 } 53 54 private void makeLookupTable(){ 55 for (Way w : ds.ways) { 56 for (Node n : w.getNodes()) { 57 if(!lookupTable.containsKey(n)) lookupTable.put(n, new HashSet<OsmPrimitive>()); 58 lookupTable.get(n).add(w); 59 } 60 } 61 for (Relation r : ds.relations) { 62 for (RelationMember m : r.getMembers()) { 63 OsmPrimitive o = m.getMember(); 64 if(!lookupTable.containsKey(o)) lookupTable.put(o, new HashSet<OsmPrimitive>()); 65 lookupTable.get(o).add(r); 66 } 67 } 44 68 } 45 69 70 /** 71 * Get the result collection 72 */ 73 public Collection<OsmPrimitive> getData(){ 74 return data; 75 } 76 77 /** 78 * Initialize data before associated visit calls 79 */ 80 public void initialize(){ 81 data = new HashSet<OsmPrimitive>(); 82 } 83 84 public void visit(OsmPrimitive o) { 85 if(lookupTable.containsKey(o)){ 86 Collection<OsmPrimitive> c = lookupTable.get(o); 87 Collection<OsmPrimitive> oldData = new HashSet<OsmPrimitive>(data); 88 data.addAll(c); 89 if(indirectRefs) 90 for(OsmPrimitive oo : c) 91 if(!oldData.contains(oo)) 92 visit(oo); 93 } 94 } 95 46 96 public void visit(Node n) { 47 for (Way w : ds.ways) { 48 if (w.isDeleted() || w.incomplete) { 49 continue; 50 } 51 for (Node n2 : w.getNodes()) { 52 if (n == n2) { 53 data.add(w); 54 if (indirectRefs) { 55 visit(w); 56 } 57 } 58 } 59 } 60 checkRelationMembership(n); 97 visit((OsmPrimitive)n); 61 98 } 62 99 63 100 public void visit(Way w) { 64 checkRelationMembership(w);101 visit((OsmPrimitive)w); 65 102 } 66 103 67 104 public void visit(Relation r) { 68 checkRelationMembership(r); 69 } 70 71 private void checkRelationMembership(OsmPrimitive p) { 72 // FIXME - this might be a candidate for optimisation 73 // if OSM primitives are made to hold a list of back 74 // references. 75 for (Relation r : ds.relations) { 76 if (r.incomplete || r.isDeleted()) { 77 continue; 78 } 79 for (RelationMember m : r.getMembers()) { 80 if (m.getMember() == p) { 81 if (!data.contains(r)) { 82 data.add(r); 83 if (indirectRefs) { 84 // move up the tree (there might be relations 85 // referring to this relation) 86 checkRelationMembership(r); 87 } 88 } 89 break; 90 } 91 } 92 } 105 visit((OsmPrimitive)r); 93 106 } 94 107 }
Note:
See TracChangeset
for help on using the changeset viewer.