Changeset 6615 in josm


Ignore:
Timestamp:
2014-01-03T19:32:18+01:00 (10 years ago)
Author:
Don-vip
Message:

fix compilation warnings + minor code refactorization

Location:
trunk/src/org
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/json/JSONArray.java

    r6484 r6615  
    8383     * The arrayList where the JSONArray's properties are kept.
    8484     */
    85     private final ArrayList myArrayList;
     85    private final ArrayList<Object> myArrayList;
    8686
    8787    /**
     
    8989     */
    9090    public JSONArray() {
    91         this.myArrayList = new ArrayList();
     91        this.myArrayList = new ArrayList<Object>();
    9292    }
    9393
     
    151151     *            A Collection.
    152152     */
    153     public JSONArray(Collection collection) {
    154         this.myArrayList = new ArrayList();
     153    public JSONArray(Collection<?> collection) {
     154        this.myArrayList = new ArrayList<Object>();
    155155        if (collection != null) {
    156             Iterator iter = collection.iterator();
     156            Iterator<?> iter = collection.iterator();
    157157            while (iter.hasNext()) {
    158158                this.myArrayList.add(JSONObject.wrap(iter.next()));
     
    594594     * @return this.
    595595     */
    596     public JSONArray put(Collection value) {
     596    public JSONArray put(Collection<?> value) {
    597597        this.put(new JSONArray(value));
    598598        return this;
     
    647647     * @return this.
    648648     */
    649     public JSONArray put(Map value) {
     649    public JSONArray put(Map<?, ?> value) {
    650650        this.put(new JSONObject(value));
    651651        return this;
     
    696696     *             If the index is negative or if the value is not finite.
    697697     */
    698     public JSONArray put(int index, Collection value) throws JSONException {
     698    public JSONArray put(int index, Collection<?> value) throws JSONException {
    699699        this.put(index, new JSONArray(value));
    700700        return this;
     
    768768     *             number.
    769769     */
    770     public JSONArray put(int index, Map value) throws JSONException {
     770    public JSONArray put(int index, Map<?, ?> value) throws JSONException {
    771771        this.put(index, new JSONObject(value));
    772772        return this;
  • trunk/src/org/json/JSONObject.java

    r6484 r6615  
    3737import java.util.Locale;
    3838import java.util.Map;
     39import java.util.Map.Entry;
    3940import java.util.ResourceBundle;
    4041import java.util.Set;
     
    136137     * The map where the JSONObject's properties are kept.
    137138     */
    138     private final Map map;
     139    private final Map<String, Object> map;
    139140
    140141    /**
     
    150151     */
    151152    public JSONObject() {
    152         this.map = new HashMap();
     153        this.map = new HashMap<String, Object>();
    153154    }
    154155
     
    240241     * @throws JSONException
    241242     */
    242     public JSONObject(Map map) {
    243         this.map = new HashMap();
     243    public JSONObject(Map<String, Object> map) {
     244        this.map = new HashMap<String, Object>();
    244245        if (map != null) {
    245             Iterator i = map.entrySet().iterator();
     246            Iterator<Entry<String, Object>> i = map.entrySet().iterator();
    246247            while (i.hasNext()) {
    247                 Map.Entry e = (Map.Entry) i.next();
     248                Entry<String, Object> e = i.next();
    248249                Object value = e.getValue();
    249250                if (value != null) {
     
    296297    public JSONObject(Object object, String names[]) {
    297298        this();
    298         Class c = object.getClass();
     299        Class<? extends Object> c = object.getClass();
    299300        for (int i = 0; i < names.length; i += 1) {
    300301            String name = names[i];
     
    339340// Iterate through the keys in the bundle.
    340341
    341         Enumeration keys = bundle.getKeys();
     342        Enumeration<?> keys = bundle.getKeys();
    342343        while (keys.hasMoreElements()) {
    343344            Object key = keys.nextElement();
     
    610611            return null;
    611612        }
    612         Iterator iterator = jo.keys();
     613        Iterator<String> iterator = jo.keys();
    613614        String[] names = new String[length];
    614615        int i = 0;
     
    629630            return null;
    630631        }
    631         Class klass = object.getClass();
     632        Class<? extends Object> klass = object.getClass();
    632633        Field[] fields = klass.getFields();
    633634        int length = fields.length;
     
    718719     * @return An iterator of the keys.
    719720     */
    720     public Iterator keys() {
     721    public Iterator<String> keys() {
    721722        return this.keySet().iterator();
    722723    }
     
    727728     * @return A keySet.
    728729     */
    729     public Set keySet() {
     730    public Set<String> keySet() {
    730731        return this.map.keySet();
    731732    }
     
    749750    public JSONArray names() {
    750751        JSONArray ja = new JSONArray();
    751         Iterator keys = this.keys();
     752        Iterator<String> keys = this.keys();
    752753        while (keys.hasNext()) {
    753754            ja.put(keys.next());
     
    979980
    980981    private void populateMap(Object bean) {
    981         Class klass = bean.getClass();
     982        Class<? extends Object> klass = bean.getClass();
    982983
    983984// If klass is a System class then set includeSuperClass to false.
     
    10511052     * @throws JSONException
    10521053     */
    1053     public JSONObject put(String key, Collection value) throws JSONException {
     1054    public JSONObject put(String key, Collection<?> value) throws JSONException {
    10541055        this.put(key, new JSONArray(value));
    10551056        return this;
     
    11151116     * @throws JSONException
    11161117     */
    1117     public JSONObject put(String key, Map value) throws JSONException {
     1118    public JSONObject put(String key, Map<String, Object> value) throws JSONException {
    11181119        this.put(key, new JSONObject(value));
    11191120        return this;
     
    14461447     *             If the value is or contains an invalid number.
    14471448     */
     1449    @SuppressWarnings("unchecked")
    14481450    public static String valueToString(Object value) throws JSONException {
    14491451        if (value == null || value.equals(null)) {
     
    14701472        }
    14711473        if (value instanceof Map) {
    1472             return new JSONObject((Map) value).toString();
     1474            return new JSONObject((Map<String, Object>) value).toString();
    14731475        }
    14741476        if (value instanceof Collection) {
    1475             return new JSONArray((Collection) value).toString();
     1477            return new JSONArray((Collection<?>) value).toString();
    14761478        }
    14771479        if (value.getClass().isArray()) {
     
    14931495     * @return The wrapped value
    14941496     */
     1497    @SuppressWarnings("unchecked")
    14951498    public static Object wrap(Object object) {
    14961499        try {
     
    15091512
    15101513            if (object instanceof Collection) {
    1511                 return new JSONArray((Collection) object);
     1514                return new JSONArray((Collection<?>) object);
    15121515            }
    15131516            if (object.getClass().isArray()) {
     
    15151518            }
    15161519            if (object instanceof Map) {
    1517                 return new JSONObject((Map) object);
     1520                return new JSONObject((Map<String, Object>) object);
    15181521            }
    15191522            Package objectPackage = object.getClass().getPackage();
     
    15441547    }
    15451548
     1549    @SuppressWarnings("unchecked")
    15461550    static final Writer writeValue(Writer writer, Object value,
    15471551            int indentFactor, int indent) throws JSONException, IOException {
     
    15531557            ((JSONArray) value).write(writer, indentFactor, indent);
    15541558        } 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);
    15561560        } else if (value instanceof Collection) {
    1557             new JSONArray((Collection) value).write(writer, indentFactor,
     1561            new JSONArray((Collection<?>) value).write(writer, indentFactor,
    15581562                    indent);
    15591563        } else if (value.getClass().isArray()) {
     
    15971601            boolean commanate = false;
    15981602            final int length = this.length();
    1599             Iterator keys = this.keys();
     1603            Iterator<String> keys = this.keys();
    16001604            writer.write('{');
    16011605
  • trunk/src/org/openstreetmap/josm/gui/MainApplet.java

    r6471 r6615  
    3232import org.openstreetmap.josm.tools.I18n;
    3333import org.openstreetmap.josm.tools.Shortcut;
     34import org.openstreetmap.josm.tools.Utils;
    3435
    3536public class MainApplet extends JApplet {
     
    180181            @Override
    181182            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("."));
    188184            }
    189185
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

    r6248 r6615  
    77import java.awt.event.ActionEvent;
    88import java.io.File;
    9 import java.net.MalformedURLException;
    109import java.net.URL;
    1110import java.util.ArrayList;
     
    3231import org.openstreetmap.josm.tools.AudioUtil;
    3332import org.openstreetmap.josm.tools.ImageProvider;
     33import org.openstreetmap.josm.tools.Utils;
    3434
    3535/**
     
    125125     */
    126126    private void importAudio(File wavFile, MarkerLayer ml, double firstStartTime, Markers markers) {
    127         URL url = null;
     127        URL url = Utils.fileToURL(wavFile);
    128128        boolean hasTracks = layer.data.tracks != null && !layer.data.tracks.isEmpty();
    129129        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         }
    135130        Collection<WayPoint> waypoints = new ArrayList<WayPoint>();
    136131        boolean timedMarkersOmitted = false;
    137132        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
    143135        WayPoint wayPointFromTimeStamp = null;
    144136
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r6380 r6615  
    3939import org.openstreetmap.josm.gui.MapView;
    4040import org.openstreetmap.josm.tools.ImageProvider;
     41import org.openstreetmap.josm.tools.Utils;
    4142import org.openstreetmap.josm.tools.template_engine.ParseError;
    4243import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
     
    210211                        // Try a relative file:// url, if the link is not in an URL-compatible form
    211212                        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));
    217214                        }
    218215                    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r6611 r6615  
    471471            final String text = args[0];
    472472            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);
    474474        }
    475475
    476476        /**
    477477         * 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
    478481         * @see String#substring(int)
    479482         */
     
    485488         * Returns the substring of {@code s} starting at index {@code begin} (inclusive)
    486489         * 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
    487494         * @see String#substring(int, int)
    488495         */
  • trunk/src/org/openstreetmap/josm/plugins/Plugin.java

    r6380 r6615  
    144144        File pluginDir = Main.pref.getPluginsDirectory();
    145145        File pluginJar = new File(pluginDir, info.name + ".jar");
    146         final URL pluginJarUrl = PluginInformation.fileToURL(pluginJar);
     146        final URL pluginJarUrl = Utils.fileToURL(pluginJar);
    147147        return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
    148148              public ClassLoader run() {
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r6544 r6615  
    527527            File pluginJar = new File(pluginDir, info.name + ".jar");
    528528            I18n.addTexts(pluginJar);
    529             URL pluginJarUrl = PluginInformation.fileToURL(pluginJar);
     529            URL pluginJarUrl = Utils.fileToURL(pluginJar);
    530530            allPluginLibraries.add(pluginJarUrl);
    531531        }
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r6571 r6615  
    9999                throw new PluginException(name, tr("The plugin file ''{0}'' does not include a Manifest.", file.toString()));
    100100            scanManifest(manifest, false);
    101             libraries.add(0, fileToURL(file));
     101            libraries.add(0, Utils.fileToURL(file));
    102102        } catch (IOException e) {
    103103            throw new PluginException(name, e);
     
    206206            }
    207207        } else {
    208             //noinspection NullArgumentToVariableArgMethod
    209             s = MessageFormat.format(s, null);
     208            s = MessageFormat.format(s, (Object[]) null);
    210209        }
    211210        description = s;
     
    263262                }
    264263
    265                 libraries.add(fileToURL(entryFile));
     264                libraries.add(Utils.fileToURL(entryFile));
    266265            }
    267266        }
     
    333332    }
    334333
    335     public static URL fileToURL(File f) {
    336         try {
    337             return f.toURI().toURL();
    338         } catch (MalformedURLException ex) {
    339             return null;
    340         }
    341     }
     334
    342335
    343336    /**
     
    395388    }
    396389
     390    /**
     391     * Returns all possible plugin locations.
     392     * @return all possible plugin locations.
     393     */
    397394    public static Collection<String> getPluginLocations() {
    398395        Collection<String> locations = Main.pref.getAllPossiblePreferenceDirs();
     
    462459
    463460    /**
    464      * Replies the name of the plugin
     461     * Replies the name of the plugin.
     462     * @return The plugin name
    465463     */
    466464    public String getName() {
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r6380 r6615  
    517517            switch (type) {
    518518            case SVG:
    519                 URI uri = getSvgUniverse().loadSVG(is, is.getFile().toURI().toURL().toString());
     519                URI uri = getSvgUniverse().loadSVG(is, Utils.fileToURL(is.getFile()).toString());
    520520                SVGDiagram svg = getSvgUniverse().getDiagram(uri);
    521521                return svg == null ? null : new ImageResource(svg);
     
    523523                BufferedImage img = null;
    524524                try {
    525                     img = ImageIO.read(is.getFile().toURI().toURL());
     525                    img = ImageIO.read(Utils.fileToURL(is.getFile()));
    526526                } catch (IOException e) {
    527527                    Main.warn("IOException while reading HTTP image: "+e.getMessage());
     
    654654            }
    655655        } 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);
    663659        }
    664660        return null;
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6610 r6615  
    2424import java.io.OutputStream;
    2525import java.net.HttpURLConnection;
     26import java.net.MalformedURLException;
    2627import java.net.URL;
    2728import java.net.URLConnection;
     
    373374        }
    374375    }
     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    }
    375393
    376394    private final static double EPSILON = 1e-11;
Note: See TracChangeset for help on using the changeset viewer.