Changeset 6615 in josm
- Timestamp:
- 2014-01-03T19:32:18+01:00 (11 years ago)
- Location:
- trunk/src/org
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/json/JSONArray.java
r6484 r6615 83 83 * The arrayList where the JSONArray's properties are kept. 84 84 */ 85 private final ArrayList myArrayList;85 private final ArrayList<Object> myArrayList; 86 86 87 87 /** … … 89 89 */ 90 90 public JSONArray() { 91 this.myArrayList = new ArrayList ();91 this.myArrayList = new ArrayList<Object>(); 92 92 } 93 93 … … 151 151 * A Collection. 152 152 */ 153 public JSONArray(Collection collection) {154 this.myArrayList = new ArrayList ();153 public JSONArray(Collection<?> collection) { 154 this.myArrayList = new ArrayList<Object>(); 155 155 if (collection != null) { 156 Iterator iter = collection.iterator();156 Iterator<?> iter = collection.iterator(); 157 157 while (iter.hasNext()) { 158 158 this.myArrayList.add(JSONObject.wrap(iter.next())); … … 594 594 * @return this. 595 595 */ 596 public JSONArray put(Collection value) {596 public JSONArray put(Collection<?> value) { 597 597 this.put(new JSONArray(value)); 598 598 return this; … … 647 647 * @return this. 648 648 */ 649 public JSONArray put(Map value) {649 public JSONArray put(Map<?, ?> value) { 650 650 this.put(new JSONObject(value)); 651 651 return this; … … 696 696 * If the index is negative or if the value is not finite. 697 697 */ 698 public JSONArray put(int index, Collection value) throws JSONException {698 public JSONArray put(int index, Collection<?> value) throws JSONException { 699 699 this.put(index, new JSONArray(value)); 700 700 return this; … … 768 768 * number. 769 769 */ 770 public JSONArray put(int index, Map value) throws JSONException {770 public JSONArray put(int index, Map<?, ?> value) throws JSONException { 771 771 this.put(index, new JSONObject(value)); 772 772 return this; -
trunk/src/org/json/JSONObject.java
r6484 r6615 37 37 import java.util.Locale; 38 38 import java.util.Map; 39 import java.util.Map.Entry; 39 40 import java.util.ResourceBundle; 40 41 import java.util.Set; … … 136 137 * The map where the JSONObject's properties are kept. 137 138 */ 138 private final Map map;139 private final Map<String, Object> map; 139 140 140 141 /** … … 150 151 */ 151 152 public JSONObject() { 152 this.map = new HashMap ();153 this.map = new HashMap<String, Object>(); 153 154 } 154 155 … … 240 241 * @throws JSONException 241 242 */ 242 public JSONObject(Map map) {243 this.map = new HashMap ();243 public JSONObject(Map<String, Object> map) { 244 this.map = new HashMap<String, Object>(); 244 245 if (map != null) { 245 Iterator i = map.entrySet().iterator();246 Iterator<Entry<String, Object>> i = map.entrySet().iterator(); 246 247 while (i.hasNext()) { 247 Map.Entry e = (Map.Entry)i.next();248 Entry<String, Object> e = i.next(); 248 249 Object value = e.getValue(); 249 250 if (value != null) { … … 296 297 public JSONObject(Object object, String names[]) { 297 298 this(); 298 Class c = object.getClass();299 Class<? extends Object> c = object.getClass(); 299 300 for (int i = 0; i < names.length; i += 1) { 300 301 String name = names[i]; … … 339 340 // Iterate through the keys in the bundle. 340 341 341 Enumeration keys = bundle.getKeys();342 Enumeration<?> keys = bundle.getKeys(); 342 343 while (keys.hasMoreElements()) { 343 344 Object key = keys.nextElement(); … … 610 611 return null; 611 612 } 612 Iterator iterator = jo.keys();613 Iterator<String> iterator = jo.keys(); 613 614 String[] names = new String[length]; 614 615 int i = 0; … … 629 630 return null; 630 631 } 631 Class klass = object.getClass();632 Class<? extends Object> klass = object.getClass(); 632 633 Field[] fields = klass.getFields(); 633 634 int length = fields.length; … … 718 719 * @return An iterator of the keys. 719 720 */ 720 public Iterator keys() {721 public Iterator<String> keys() { 721 722 return this.keySet().iterator(); 722 723 } … … 727 728 * @return A keySet. 728 729 */ 729 public Set keySet() {730 public Set<String> keySet() { 730 731 return this.map.keySet(); 731 732 } … … 749 750 public JSONArray names() { 750 751 JSONArray ja = new JSONArray(); 751 Iterator keys = this.keys();752 Iterator<String> keys = this.keys(); 752 753 while (keys.hasNext()) { 753 754 ja.put(keys.next()); … … 979 980 980 981 private void populateMap(Object bean) { 981 Class klass = bean.getClass();982 Class<? extends Object> klass = bean.getClass(); 982 983 983 984 // If klass is a System class then set includeSuperClass to false. … … 1051 1052 * @throws JSONException 1052 1053 */ 1053 public JSONObject put(String key, Collection value) throws JSONException {1054 public JSONObject put(String key, Collection<?> value) throws JSONException { 1054 1055 this.put(key, new JSONArray(value)); 1055 1056 return this; … … 1115 1116 * @throws JSONException 1116 1117 */ 1117 public JSONObject put(String key, Map value) throws JSONException {1118 public JSONObject put(String key, Map<String, Object> value) throws JSONException { 1118 1119 this.put(key, new JSONObject(value)); 1119 1120 return this; … … 1446 1447 * If the value is or contains an invalid number. 1447 1448 */ 1449 @SuppressWarnings("unchecked") 1448 1450 public static String valueToString(Object value) throws JSONException { 1449 1451 if (value == null || value.equals(null)) { … … 1470 1472 } 1471 1473 if (value instanceof Map) { 1472 return new JSONObject((Map ) value).toString();1474 return new JSONObject((Map<String, Object>) value).toString(); 1473 1475 } 1474 1476 if (value instanceof Collection) { 1475 return new JSONArray((Collection ) value).toString();1477 return new JSONArray((Collection<?>) value).toString(); 1476 1478 } 1477 1479 if (value.getClass().isArray()) { … … 1493 1495 * @return The wrapped value 1494 1496 */ 1497 @SuppressWarnings("unchecked") 1495 1498 public static Object wrap(Object object) { 1496 1499 try { … … 1509 1512 1510 1513 if (object instanceof Collection) { 1511 return new JSONArray((Collection ) object);1514 return new JSONArray((Collection<?>) object); 1512 1515 } 1513 1516 if (object.getClass().isArray()) { … … 1515 1518 } 1516 1519 if (object instanceof Map) { 1517 return new JSONObject((Map ) object);1520 return new JSONObject((Map<String, Object>) object); 1518 1521 } 1519 1522 Package objectPackage = object.getClass().getPackage(); … … 1544 1547 } 1545 1548 1549 @SuppressWarnings("unchecked") 1546 1550 static final Writer writeValue(Writer writer, Object value, 1547 1551 int indentFactor, int indent) throws JSONException, IOException { … … 1553 1557 ((JSONArray) value).write(writer, indentFactor, indent); 1554 1558 } else if (value instanceof Map) { 1555 new JSONObject((Map ) value).write(writer, indentFactor, indent);1559 new JSONObject((Map<String, Object>) value).write(writer, indentFactor, indent); 1556 1560 } else if (value instanceof Collection) { 1557 new JSONArray((Collection ) value).write(writer, indentFactor,1561 new JSONArray((Collection<?>) value).write(writer, indentFactor, 1558 1562 indent); 1559 1563 } else if (value.getClass().isArray()) { … … 1597 1601 boolean commanate = false; 1598 1602 final int length = this.length(); 1599 Iterator keys = this.keys();1603 Iterator<String> keys = this.keys(); 1600 1604 writer.write('{'); 1601 1605 -
trunk/src/org/openstreetmap/josm/gui/MainApplet.java
r6471 r6615 32 32 import org.openstreetmap.josm.tools.I18n; 33 33 import org.openstreetmap.josm.tools.Shortcut; 34 import org.openstreetmap.josm.tools.Utils; 34 35 35 36 public class MainApplet extends JApplet { … … 180 181 @Override 181 182 public URL getCodeBase() { 182 try { 183 return new File(".").toURI().toURL(); 184 } catch (Exception e) { 185 e.printStackTrace(); 186 return null; 187 } 183 return Utils.fileToURL(new File(".")); 188 184 } 189 185 -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java
r6248 r6615 7 7 import java.awt.event.ActionEvent; 8 8 import java.io.File; 9 import java.net.MalformedURLException;10 9 import java.net.URL; 11 10 import java.util.ArrayList; … … 32 31 import org.openstreetmap.josm.tools.AudioUtil; 33 32 import org.openstreetmap.josm.tools.ImageProvider; 33 import org.openstreetmap.josm.tools.Utils; 34 34 35 35 /** … … 125 125 */ 126 126 private void importAudio(File wavFile, MarkerLayer ml, double firstStartTime, Markers markers) { 127 URL url = null;127 URL url = Utils.fileToURL(wavFile); 128 128 boolean hasTracks = layer.data.tracks != null && !layer.data.tracks.isEmpty(); 129 129 boolean hasWaypoints = layer.data.waypoints != null && !layer.data.waypoints.isEmpty(); 130 try {131 url = wavFile.toURI().toURL();132 } catch (MalformedURLException e) {133 Main.error("Unable to convert filename " + wavFile.getAbsolutePath() + " to URL");134 }135 130 Collection<WayPoint> waypoints = new ArrayList<WayPoint>(); 136 131 boolean timedMarkersOmitted = false; 137 132 boolean untimedMarkersOmitted = false; 138 double snapDistance = Main.pref.getDouble("marker.audiofromuntimedwaypoints.distance", 1.0e-3); /* 139 * about 140 * 25 141 * m 142 */ 133 double snapDistance = Main.pref.getDouble("marker.audiofromuntimedwaypoints.distance", 1.0e-3); 134 // about 25 m 143 135 WayPoint wayPointFromTimeStamp = null; 144 136 -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r6380 r6615 39 39 import org.openstreetmap.josm.gui.MapView; 40 40 import org.openstreetmap.josm.tools.ImageProvider; 41 import org.openstreetmap.josm.tools.Utils; 41 42 import org.openstreetmap.josm.tools.template_engine.ParseError; 42 43 import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider; … … 210 211 // Try a relative file:// url, if the link is not in an URL-compatible form 211 212 if (relativePath != null) { 212 try { 213 url = new File(relativePath.getParentFile(), uri).toURI().toURL(); 214 } catch (MalformedURLException e1) { 215 Main.warn("Unable to convert uri {0} to URL: {1}", uri, e1.getMessage()); 216 } 213 url = Utils.fileToURL(new File(relativePath.getParentFile(), uri)); 217 214 } 218 215 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java
r6611 r6615 471 471 final String text = args[0]; 472 472 System.arraycopy(args, 1, args, 0, args.length - 1); 473 return org.openstreetmap.josm.tools.I18n.tr(text, args);473 return org.openstreetmap.josm.tools.I18n.tr(text, (Object[])args); 474 474 } 475 475 476 476 /** 477 477 * Returns the substring of {@code s} starting at index {@code begin} (inclusive, 0-indexed). 478 * @param s The base string 479 * @param begin The start index 480 * @return the substring 478 481 * @see String#substring(int) 479 482 */ … … 485 488 * Returns the substring of {@code s} starting at index {@code begin} (inclusive) 486 489 * and ending at index {@code end}, (exclusive, 0-indexed). 490 * @param s The base string 491 * @param begin The start index 492 * @param end The end index 493 * @return the substring 487 494 * @see String#substring(int, int) 488 495 */ -
trunk/src/org/openstreetmap/josm/plugins/Plugin.java
r6380 r6615 144 144 File pluginDir = Main.pref.getPluginsDirectory(); 145 145 File pluginJar = new File(pluginDir, info.name + ".jar"); 146 final URL pluginJarUrl = PluginInformation.fileToURL(pluginJar);146 final URL pluginJarUrl = Utils.fileToURL(pluginJar); 147 147 return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { 148 148 public ClassLoader run() { -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r6544 r6615 527 527 File pluginJar = new File(pluginDir, info.name + ".jar"); 528 528 I18n.addTexts(pluginJar); 529 URL pluginJarUrl = PluginInformation.fileToURL(pluginJar);529 URL pluginJarUrl = Utils.fileToURL(pluginJar); 530 530 allPluginLibraries.add(pluginJarUrl); 531 531 } -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r6571 r6615 99 99 throw new PluginException(name, tr("The plugin file ''{0}'' does not include a Manifest.", file.toString())); 100 100 scanManifest(manifest, false); 101 libraries.add(0, fileToURL(file));101 libraries.add(0, Utils.fileToURL(file)); 102 102 } catch (IOException e) { 103 103 throw new PluginException(name, e); … … 206 206 } 207 207 } else { 208 //noinspection NullArgumentToVariableArgMethod 209 s = MessageFormat.format(s, null); 208 s = MessageFormat.format(s, (Object[]) null); 210 209 } 211 210 description = s; … … 263 262 } 264 263 265 libraries.add( fileToURL(entryFile));264 libraries.add(Utils.fileToURL(entryFile)); 266 265 } 267 266 } … … 333 332 } 334 333 335 public static URL fileToURL(File f) { 336 try { 337 return f.toURI().toURL(); 338 } catch (MalformedURLException ex) { 339 return null; 340 } 341 } 334 342 335 343 336 /** … … 395 388 } 396 389 390 /** 391 * Returns all possible plugin locations. 392 * @return all possible plugin locations. 393 */ 397 394 public static Collection<String> getPluginLocations() { 398 395 Collection<String> locations = Main.pref.getAllPossiblePreferenceDirs(); … … 462 459 463 460 /** 464 * Replies the name of the plugin 461 * Replies the name of the plugin. 462 * @return The plugin name 465 463 */ 466 464 public String getName() { -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r6380 r6615 517 517 switch (type) { 518 518 case SVG: 519 URI uri = getSvgUniverse().loadSVG(is, is.getFile().toURI().toURL().toString());519 URI uri = getSvgUniverse().loadSVG(is, Utils.fileToURL(is.getFile()).toString()); 520 520 SVGDiagram svg = getSvgUniverse().getDiagram(uri); 521 521 return svg == null ? null : new ImageResource(svg); … … 523 523 BufferedImage img = null; 524 524 try { 525 img = ImageIO.read( is.getFile().toURI().toURL());525 img = ImageIO.read(Utils.fileToURL(is.getFile())); 526 526 } catch (IOException e) { 527 527 Main.warn("IOException while reading HTTP image: "+e.getMessage()); … … 654 654 } 655 655 } else { 656 try { 657 File f = new File(path, name); 658 if ((path != null || f.isAbsolute()) && f.exists()) 659 return f.toURI().toURL(); 660 } catch (MalformedURLException e) { 661 Main.warn(e); 662 } 656 File f = new File(path, name); 657 if ((path != null || f.isAbsolute()) && f.exists()) 658 return Utils.fileToURL(f); 663 659 } 664 660 return null; -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r6610 r6615 24 24 import java.io.OutputStream; 25 25 import java.net.HttpURLConnection; 26 import java.net.MalformedURLException; 26 27 import java.net.URL; 27 28 import java.net.URLConnection; … … 373 374 } 374 375 } 376 377 /** 378 * Converts the given file to its URL. 379 * @param f The file to get URL from 380 * @return The URL of the given file, or {@code null} if not possible. 381 * @since 6615 382 */ 383 public static URL fileToURL(File f) { 384 if (f != null) { 385 try { 386 return f.toURI().toURL(); 387 } catch (MalformedURLException ex) { 388 Main.error("Unable to convert filename " + f.getAbsolutePath() + " to URL"); 389 } 390 } 391 return null; 392 } 375 393 376 394 private final static double EPSILON = 1e-11;
Note:
See TracChangeset
for help on using the changeset viewer.