Changeset 4113 in josm
- Timestamp:
- 2011-06-01T21:50:26+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/APIDataSet.java
r4104 r4113 20 20 import org.openstreetmap.josm.data.osm.Node; 21 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.data.osm.OsmPrimitiveComparator; 22 23 import org.openstreetmap.josm.data.osm.PrimitiveId; 23 24 import org.openstreetmap.josm.data.osm.Relation; … … 70 71 } 71 72 } 72 sortDeleted(); 73 sortNew(); 74 sortUpdated(); 75 } 76 77 /** 78 * Ensures that primitives are deleted in the following order: Relations, then Ways, 79 * then Nodes. 80 * 81 */ 82 protected void sortDeleted() { 83 Collections.sort( 84 toDelete, 85 new Comparator<OsmPrimitive>() { 86 public int compare(OsmPrimitive o1, OsmPrimitive o2) { 87 if (o1 instanceof Node && o2 instanceof Node) 88 return 0; 89 else if (o1 instanceof Node) 90 return 1; 91 else if (o2 instanceof Node) 92 return -1; 93 94 if (o1 instanceof Way && o2 instanceof Way) 95 return 0; 96 else if (o1 instanceof Way && o2 instanceof Relation) 97 return 1; 98 else if (o2 instanceof Way && o1 instanceof Relation) 99 return -1; 100 101 return 0; 102 } 103 } 104 ); 105 } 106 107 /** 108 * Ensures that primitives are added in the following order: Nodes, then Ways, 109 * then Relations. 110 * 111 */ 112 protected void sortNew() { 113 Collections.sort( 114 toAdd, 115 new Comparator<OsmPrimitive>() { 116 public int compare(OsmPrimitive o1, OsmPrimitive o2) { 117 if (o1 instanceof Node && o2 instanceof Node) 118 return 0; 119 else if (o1 instanceof Node) 120 return -1; 121 else if (o2 instanceof Node) 122 return 1; 123 124 if (o1 instanceof Way && o2 instanceof Way) 125 return 0; 126 else if (o1 instanceof Way && o2 instanceof Relation) 127 return -1; 128 else if (o2 instanceof Way && o1 instanceof Relation) 129 return 1; 130 131 return 0; 132 } 133 } 134 ); 135 } 136 /* 137 * Sort list of updated elements, so it looks neat in the confirmation dialog. 138 */ 139 protected void sortUpdated() { 140 Collections.sort( 141 toUpdate, 142 new Comparator<OsmPrimitive>() { 143 public int compare(OsmPrimitive o1, OsmPrimitive o2) { 144 if (o1 instanceof Node && o2 instanceof Node) 145 return 0; 146 else if (o1 instanceof Node) 147 return -1; 148 else if (o2 instanceof Node) 149 return 1; 150 151 if (o1 instanceof Way && o2 instanceof Way) 152 return 0; 153 else if (o1 instanceof Way && o2 instanceof Relation) 154 return -1; 155 else if (o2 instanceof Way && o1 instanceof Relation) 156 return 1; 157 158 return 0; 159 } 160 } 161 ); 162 } 163 73 OsmPrimitiveComparator c = new OsmPrimitiveComparator(); 74 c.relationsFirst = true; 75 Collections.sort(toDelete, c); 76 Collections.sort(toAdd, c); 77 Collections.sort(toUpdate, c); 78 } 79 164 80 /** 165 81 * initializes the API data set with the modified primitives in <code>ds</code> … … 236 152 } 237 153 } 238 sortNew(); 239 sortDeleted(); 154 OsmPrimitiveComparator c = new OsmPrimitiveComparator(); 155 c.relationsFirst = true; 156 Collections.sort(toDelete, c); 157 Collections.sort(toAdd, c); 158 Collections.sort(toUpdate, c); 240 159 } 241 160 -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r4068 r4113 51 51 import org.openstreetmap.josm.data.osm.Node; 52 52 import org.openstreetmap.josm.data.osm.OsmPrimitive; 53 import org.openstreetmap.josm.data.osm.OsmPrimitiveComparator; 53 54 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 54 55 import org.openstreetmap.josm.data.osm.Relation; … … 916 917 } 917 918 918 /** Comparator, comparing by type and objects display names */ 919 static private class OsmPrimitiveComparator implements Comparator<OsmPrimitive> { 920 final private HashMap<OsmPrimitive, String> cache= new HashMap<OsmPrimitive, String>(); 921 final private DefaultNameFormatter df = DefaultNameFormatter.getInstance(); 922 923 private String cachedName(OsmPrimitive p) { 924 String name = cache.get(p); 925 if (name == null) { 926 name = p.getDisplayName(df); 927 cache.put(p, name); 928 } 929 return name; 930 } 931 932 private int compareName(OsmPrimitive a, OsmPrimitive b) { 933 String an = cachedName(a); 934 String bn = cachedName(b); 935 // make sure display names starting with digits are the end of the 936 // list 937 if (Character.isDigit(an.charAt(0)) && Character.isDigit(bn.charAt(0))) 938 return an.compareTo(bn); 939 else if (Character.isDigit(an.charAt(0)) && !Character.isDigit(bn.charAt(0))) 940 return 1; 941 else if (!Character.isDigit(an.charAt(0)) && Character.isDigit(bn.charAt(0))) 942 return -1; 943 return an.compareTo(bn); 919 /** Quicker comparator, comparing just by type and ID's */ 920 static private class OsmPrimitiveQuickComparator implements Comparator<OsmPrimitive> { 921 922 private int compareId(OsmPrimitive a, OsmPrimitive b) { 923 long id_a=a.getUniqueId(); 924 long id_b=b.getUniqueId(); 925 if (id_a<id_b) return -1; 926 if (id_a>id_b) return 1; 927 return 0; 944 928 } 945 929 … … 956 940 public int compare(OsmPrimitive a, OsmPrimitive b) { 957 941 if (a.getType().equals(b.getType())) 958 return compareName(a, b);959 return compareType(a, b);960 }961 }962 963 /** Quicker comparator, comparing just by type and ID's */964 static private class OsmPrimitiveQuickComparator implements Comparator<OsmPrimitive> {965 966 private int compareId(OsmPrimitive a, OsmPrimitive b) {967 long id_a=a.getUniqueId();968 long id_b=b.getUniqueId();969 if (id_a<id_b) return -1;970 if (id_a>id_b) return 1;971 return 0;972 }973 974 private int compareType(OsmPrimitive a, OsmPrimitive b) {975 // show ways before relations, then nodes976 if (a.getType().equals(OsmPrimitiveType.WAY)) return -1;977 if (a.getType().equals(OsmPrimitiveType.NODE)) return 1;978 // a is a relation979 if (b.getType().equals(OsmPrimitiveType.WAY)) return 1;980 // b is a node981 return -1;982 }983 984 public int compare(OsmPrimitive a, OsmPrimitive b) {985 if (a.getType().equals(b.getType()))986 942 return compareId(a, b); 987 943 return compareType(a, b);
Note:
See TracChangeset
for help on using the changeset viewer.