You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2007/12/11 13:58:44 UTC

svn commit: r603232 - in /incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json: JSONArray.java JSONObject.java

Author: cziegeler
Date: Tue Dec 11 04:58:44 2007
New Revision: 603232

URL: http://svn.apache.org/viewvc?rev=603232&view=rev
Log:
Use java5 features and use linked hash map in order persist the order of properties inside the map.

Modified:
    incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/JSONArray.java
    incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/JSONObject.java

Modified: incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/JSONArray.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/JSONArray.java?rev=603232&r1=603231&r2=603232&view=diff
==============================================================================
--- incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/JSONArray.java (original)
+++ incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/JSONArray.java Tue Dec 11 04:58:44 2007
@@ -86,14 +86,14 @@
     /**
      * The arrayList where the JSONArray's properties are kept.
      */
-    private ArrayList myArrayList;
+    private ArrayList<Object> myArrayList;
 
 
     /**
      * Construct an empty JSONArray.
      */
     public JSONArray() {
-        this.myArrayList = new ArrayList();
+        this.myArrayList = new ArrayList<Object>();
     }
 
     /**
@@ -151,10 +151,10 @@
      * Construct a JSONArray from a Collection.
      * @param collection     A Collection.
      */
-    public JSONArray(Collection collection) {
+    public JSONArray(Collection<Object> collection) {
         this.myArrayList = (collection == null) ?
-        	new ArrayList() :
-	        new ArrayList(collection);
+        	new ArrayList<Object>() :
+	        new ArrayList<Object>(collection);
     }
 
 
@@ -210,7 +210,7 @@
         Object o = get(index);
         try {
             return o instanceof Number ?
-                ((Number)o).doubleValue() : 
+                ((Number)o).doubleValue() :
                 Double.valueOf((String)o).doubleValue();
         } catch (Exception e) {
             throw new JSONException("JSONArray[" + index +
@@ -546,7 +546,7 @@
         put(new JSONArray(value));
         return this;
     }
-    
+
 
     /**
      * Append a double value. This increases the array's length by one.
@@ -597,8 +597,8 @@
         put(new JSONObject(value));
         return this;
     }
-    
-    
+
+
     /**
      * Append an object value. This increases the array's length by one.
      * @param value An object value.  The value should be a
@@ -626,7 +626,7 @@
         return this;
     }
 
-    
+
     /**
      * Put a value in the JSONArray, where the value will be a
      * JSONArray which is produced from a Collection.
@@ -641,7 +641,7 @@
         return this;
     }
 
-    
+
     /**
      * Put or replace a double value. If the index is greater than the length of
      *  the JSONArray, then null elements will be added as necessary to pad
@@ -701,8 +701,8 @@
         put(index, new JSONObject(value));
         return this;
     }
-    
-    
+
+
     /**
      * Put or replace an object value in the JSONArray. If the index is greater
      *  than the length of the JSONArray, then null elements will be added as

Modified: incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/JSONObject.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/JSONObject.java?rev=603232&r1=603231&r2=603232&view=diff
==============================================================================
--- incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/JSONObject.java (original)
+++ incubator/sling/trunk/commons/json/src/main/java/org/apache/sling/commons/json/JSONObject.java Tue Dec 11 04:58:44 2007
@@ -28,8 +28,8 @@
 import java.io.Writer;
 import java.lang.reflect.Field;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 /**
@@ -128,7 +128,7 @@
     /**
      * The hash map where the JSONObject's properties are kept.
      */
-    private HashMap<String, Object> myHashMap;
+    private Map<String, Object> myHashMap;
 
 
     /**
@@ -144,7 +144,7 @@
      * Construct an empty JSONObject.
      */
     public JSONObject() {
-        this.myHashMap = new HashMap<String, Object>();
+        this.myHashMap = new LinkedHashMap<String, Object>();
     }
 
 
@@ -231,8 +231,8 @@
      */
     public JSONObject(Map<String, Object> map) {
         this.myHashMap = (map == null) ?
-        	new HashMap<String, Object>() :
-        	new HashMap<String, Object>(map);
+        	new LinkedHashMap<String, Object>() :
+        	new LinkedHashMap<String, Object>(map);
     }