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

fix compilation warnings + minor code refactorization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified 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
Note: See TracChangeset for help on using the changeset viewer.