---
core-dave/src/org/openstreetmap/josm/data/osm/DataSet.java | 21 ++++++-------
1 file changed, 11 insertions(+), 10 deletions(-)
diff -puN src/org/openstreetmap/josm/data/osm/DataSet.java~optimize-selection-code src/org/openstreetmap/josm/data/osm/DataSet.java
|
a
|
b
|
public class DataSet implements Cloneabl
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | public Collection<OsmPrimitive> getSelectedNodesAndWays() { |
| 152 | | Collection<OsmPrimitive> sel = getSelected(nodes); |
| 153 | | sel.addAll(getSelected(ways)); |
| | 152 | Collection<OsmPrimitive> sel = new LinkedList<OsmPrimitive>(); |
| | 153 | for (OsmPrimitive osm : selectedPrimitives) { |
| | 154 | if (osm instanceof Way || |
| | 155 | osm instanceof Node) |
| | 156 | sel.add(osm); |
| | 157 | } |
| 154 | 158 | return sel; |
| 155 | 159 | } |
| 156 | 160 | |
| … |
… |
public class DataSet implements Cloneabl
|
| 253 | 257 | * @param fireSelectionChangeEvent true, if the selection change listeners are to be notified; false, otherwise |
| 254 | 258 | */ |
| 255 | 259 | public void setSelected(Collection<? extends OsmPrimitive> selection, boolean fireSelectionChangeEvent) { |
| 256 | | clearSelection(nodes); |
| 257 | | clearSelection(ways); |
| 258 | | clearSelection(relations); |
| 259 | | addSelected(selection); |
| | 260 | selectedPrimitives = new LinkedHashSet<OsmPrimitive>(selection); |
| 260 | 261 | if (fireSelectionChangeEvent) { |
| 261 | 262 | fireSelectionChanged(selection); |
| 262 | 263 | } |
| … |
… |
public class DataSet implements Cloneabl
|
| 290 | 291 | * @param fireSelectionChangeEvent true, if the selection change listeners are to be notified; false, otherwise |
| 291 | 292 | */ |
| 292 | 293 | public void addSelected(Collection<? extends OsmPrimitive> selection, boolean fireSelectionChangeEvent) { |
| 293 | | for (OsmPrimitive osm : selection) { |
| 294 | | osm.setSelected(true); |
| 295 | | } |
| 296 | 294 | selectedPrimitives.addAll(selection); |
| 297 | 295 | if (fireSelectionChangeEvent) { |
| 298 | 296 | fireSelectionChanged(selection); |
| … |
… |
public class DataSet implements Cloneabl
|
| 307 | 305 | } |
| 308 | 306 | List<OsmPrimitive> list = Arrays.asList(osm); |
| 309 | 307 | setSelected(list); |
| 310 | | fireSelectionChanged(Arrays.asList(osm)); |
| | 308 | fireSelectionChanged(list); |
| 311 | 309 | } |
| 312 | 310 | |
| 313 | 311 | /** |
| … |
… |
public class DataSet implements Cloneabl
|
| 353 | 351 | private Collection<OsmPrimitive> getSelected(Collection<? extends OsmPrimitive> list) { |
| 354 | 352 | if (list == null) |
| 355 | 353 | return new LinkedList<OsmPrimitive>(); |
| | 354 | // getSelected() is called with large lists, so |
| | 355 | // creating the return list from the selection |
| | 356 | // should be faster most of the time. |
| 356 | 357 | Collection<OsmPrimitive> sel = new LinkedHashSet<OsmPrimitive>(selectedPrimitives); |
| 357 | 358 | sel.retainAll(list); |
| 358 | 359 | return sel; |