@@ -32,15 +32,8 @@ of this software and associated documentation files (the "Software"), to deal
3232import java .lang .reflect .Modifier ;
3333import java .math .BigDecimal ;
3434import java .math .BigInteger ;
35- import java .util .Collection ;
36- import java .util .Enumeration ;
37- import java .util .HashMap ;
38- import java .util .Iterator ;
39- import java .util .Locale ;
40- import java .util .Map ;
35+ import java .util .*;
4136import java .util .Map .Entry ;
42- import java .util .ResourceBundle ;
43- import java .util .Set ;
4437
4538/**
4639 * A JSONObject is an unordered collection of name/value pairs. Its external
@@ -164,13 +157,13 @@ public String toString() {
164157 * Construct an empty JSONObject.
165158 */
166159 public JSONObject () {
167- // HashMap is used on purpose to ensure that elements are unordered by
160+ // LinkedHashMap is used on purpose to ensure that elements are unordered by
168161 // the specification.
169162 // JSON tends to be a portable transfer format to allows the container
170163 // implementations to rearrange their items for a faster element
171164 // retrieval based on associative access.
172165 // Therefore, an implementation mustn't rely on the order of the item.
173- this .map = new HashMap <String , Object >();
166+ this .map = new LinkedHashMap <String , Object >();
174167 }
175168
176169 /**
@@ -257,9 +250,9 @@ public JSONObject(JSONTokener x) throws JSONException {
257250 */
258251 public JSONObject (Map <?, ?> m ) {
259252 if (m == null ) {
260- this .map = new HashMap <String , Object >();
253+ this .map = new LinkedHashMap <String , Object >();
261254 } else {
262- this .map = new HashMap <String , Object >(m .size ());
255+ this .map = new LinkedHashMap <String , Object >(m .size ());
263256 for (final Entry <?, ?> e : m .entrySet ()) {
264257 final Object value = e .getValue ();
265258 if (value != null ) {
@@ -388,7 +381,7 @@ public JSONObject(String baseName, Locale locale) throws JSONException {
388381 * @param initialCapacity initial capacity of the internal map.
389382 */
390383 protected JSONObject (int initialCapacity ){
391- this .map = new HashMap <String , Object >(initialCapacity );
384+ this .map = new LinkedHashMap <String , Object >(initialCapacity );
392385 }
393386
394387 /**
@@ -2315,7 +2308,7 @@ public Writer write(Writer writer, int indentFactor, int indent)
23152308 * @return a java.util.Map containing the entries of this object
23162309 */
23172310 public Map <String , Object > toMap () {
2318- Map <String , Object > results = new HashMap <String , Object >();
2311+ Map <String , Object > results = new LinkedHashMap <String , Object >();
23192312 for (Entry <String , Object > entry : this .entrySet ()) {
23202313 Object value ;
23212314 if (entry .getValue () == null || NULL .equals (entry .getValue ())) {
0 commit comments