Changeset 1121 in josm
- Timestamp:
- 2008-12-13T23:24:29+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r1082 r1121 12 12 import java.util.Arrays; 13 13 import java.util.Collection; 14 import java.util.Collections; 14 15 import java.util.LinkedList; 15 16 import java.util.Map; 16 17 import java.util.Properties; 17 18 import java.util.SortedMap; 18 import java.util.StringTokenizer;19 19 import java.util.TreeMap; 20 20 import java.util.Map.Entry; 21 import java.util.regex.Matcher; 22 import java.util.regex.Pattern; 21 23 22 24 import org.openstreetmap.josm.Main; … … 49 51 * @author imi 50 52 */ 51 public static class Bookmark {53 public static class Bookmark implements Comparable<Bookmark> { 52 54 public String name; 53 55 public double[] latlon = new double[4]; // minlat, minlon, maxlat, maxlon 54 56 @Override public String toString() { 55 57 return name; 58 } 59 public int compareTo(Bookmark b) { 60 return name.toLowerCase().compareTo(b.name.toLowerCase()); 56 61 } 57 62 } … … 290 295 BufferedReader in = new BufferedReader(new FileReader(bookmarkFile)); 291 296 292 Collection<Bookmark> bookmarks = new LinkedList<Bookmark>(); 297 LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>(); 298 // use pattern matches to scan text, as text may contain a "," itself 293 299 for (String line = in.readLine(); line != null; line = in.readLine()) { 294 StringTokenizer st = new StringTokenizer(line, ","); 295 if (st.countTokens() < 5) 296 continue; 297 Bookmark b = new Bookmark(); 298 b.name = st.nextToken(); 299 try { 300 Matcher m = Pattern.compile("^(.+),(-?\\d+.\\d+),(-?\\d+.\\d+),(-?\\d+.\\d+),(-?\\d+.\\d+)$").matcher(line); 301 if(m.matches()) 302 { 303 Bookmark b = new Bookmark(); 304 b.name = m.group(1); 300 305 for (int i = 0; i < b.latlon.length; ++i) 301 b.latlon[i] = Double.parseDouble( st.nextToken());306 b.latlon[i] = Double.parseDouble(m.group(i+2)); 302 307 bookmarks.add(b); 303 } catch (NumberFormatException x) {304 // line not parsed305 308 } 306 309 } 307 310 in.close(); 311 Collections.sort(bookmarks); 308 312 return bookmarks; 309 313 } … … 315 319 PrintWriter out = new PrintWriter(new FileWriter(bookmarkFile)); 316 320 for (Bookmark b : bookmarks) { 317 b.name = b.name.replace(',', '_');318 321 out.print(b.name+","); 319 322 for (int i = 0; i < b.latlon.length; ++i)
Note:
See TracChangeset
for help on using the changeset viewer.