Changeset 7120 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2014-05-14T02:16:44+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/APIDataSet.java
r7005 r7120 76 76 } 77 77 } 78 OsmPrimitiveComparator c = new OsmPrimitiveComparator(); 79 c.relationsFirst = true; 78 OsmPrimitiveComparator c = new OsmPrimitiveComparator(false, true); 80 79 Collections.sort(toDelete, c); 81 80 Collections.sort(toAdd, c); -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveComparator.java
r7005 r7120 8 8 import org.openstreetmap.josm.gui.DefaultNameFormatter; 9 9 10 /** Comparator, comparing by type and objects display names */ 10 /** 11 * Comparator, comparing pritimives by:<ul> 12 * <li>type and ids in "quick" mode</li> 13 * <li>type and objects display names instead</li> 14 * </ul> 15 * @since 4113 16 */ 11 17 public class OsmPrimitiveComparator implements Comparator<OsmPrimitive> { 12 private final Map<OsmPrimitive, String> cache= new HashMap<>(); 13 private final DefaultNameFormatter df = DefaultNameFormatter.getInstance(); 14 public boolean relationsFirst = false; 18 private final Map<OsmPrimitive, String> cache = new HashMap<>(); 19 private final boolean relationsFirst; 20 private final boolean quick; 21 22 /** 23 * Constructs a new {@code OsmPrimitiveComparator}. 24 */ 25 public OsmPrimitiveComparator() { 26 this(false, false); 27 } 28 29 /** 30 * Constructs a new {@code OsmPrimitiveComparator}. 31 * @param quick if {@code true}, sorts by type and ids (fast), otherwise sort by type and display names (slower) 32 * @param relationsFirst if {@code true}, always list relations first 33 */ 34 public OsmPrimitiveComparator(boolean quick, boolean relationsFirst) { 35 this.quick = quick; 36 this.relationsFirst = relationsFirst; 37 } 15 38 16 39 private String cachedName(OsmPrimitive p) { 17 40 String name = cache.get(p); 18 41 if (name == null) { 19 name = p.getDisplayName( df);42 name = p.getDisplayName(DefaultNameFormatter.getInstance()); 20 43 cache.put(p, name); 21 44 } … … 36 59 } 37 60 61 private static int compareId(OsmPrimitive a, OsmPrimitive b) { 62 long idA = a.getUniqueId(); 63 long idB = b.getUniqueId(); 64 if (idA < idB) return -1; 65 if (idA > idB) return 1; 66 return 0; 67 } 68 38 69 private int compareType(OsmPrimitive a, OsmPrimitive b) { 39 if (relationsFirst) {70 if (relationsFirst) { 40 71 // show relations before ways, then nodes 41 72 if (a.getType().equals(OsmPrimitiveType.RELATION)) return -1; … … 58 89 public int compare(OsmPrimitive a, OsmPrimitive b) { 59 90 if (a.getType().equals(b.getType())) 60 return compareName(a, b);91 return quick ? compareId(a, b) : compareName(a, b); 61 92 return compareType(a, b); 62 93 }
Note:
See TracChangeset
for help on using the changeset viewer.