Changeset 3102 in josm for trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
- Timestamp:
- 10.03.2010 10:00:20 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r3008 r3102 9 9 import java.util.Collection; 10 10 import java.util.Collections; 11 import java.util.Comparator;12 11 import java.util.HashMap; 13 12 import java.util.HashSet; … … 313 312 314 313 /** 315 * Return a list of all selected objects. Even keys are returned. 316 * @return List of all selected objects. 314 * Replies an unmodifiable collection of primitives currently selected 315 * in this dataset 316 * 317 * @return unmodifiable collection of primitives 317 318 */ 318 319 public Collection<OsmPrimitive> getSelected() { 319 // It would be nice to have this be a copy-on-write list 320 // or an Collections.unmodifiableList(). It would be 321 // much faster for large selections. May users just 322 // call this, and only check the .size(). 323 return new ArrayList<OsmPrimitive>(selectedPrimitives); 320 return Collections.unmodifiableSet(selectedPrimitives); 324 321 } 325 322 … … 610 607 } 611 608 return a; 612 }613 614 // Provide well-defined sorting for collections of OsmPrimitives.615 // FIXME: probably not a good place to put this code.616 public static OsmPrimitive[] sort(Collection<? extends OsmPrimitive> list) {617 OsmPrimitive[] selArr = new OsmPrimitive[list.size()];618 final HashMap<Object, String> h = new HashMap<Object, String>();619 selArr = list.toArray(selArr);620 Arrays.sort(selArr, new Comparator<OsmPrimitive>() {621 public int compare(OsmPrimitive a, OsmPrimitive b) {622 if (a.getClass() == b.getClass()) {623 String as = h.get(a);624 if (as == null) {625 as = a.getName() != null ? a.getName() : Long.toString(a.getId());626 h.put(a, as);627 }628 String bs = h.get(b);629 if (bs == null) {630 bs = b.getName() != null ? b.getName() : Long.toString(b.getId());631 h.put(b, bs);632 }633 int res = as.compareTo(bs);634 if (res != 0)635 return res;636 }637 return a.compareTo(b);638 }639 });640 return selArr;641 609 } 642 610
Note: See TracChangeset
for help on using the changeset viewer.
