Skip to content

Commit 6fda2ac

Browse files
committed
Changed all HashMap to LinkedHashMap
1 parent 5024f2d commit 6fda2ac

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

JSONObject.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,8 @@ of this software and associated documentation files (the "Software"), to deal
3232
import java.lang.reflect.Modifier;
3333
import java.math.BigDecimal;
3434
import 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.*;
4136
import 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())) {

XMLTokener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public class XMLTokener extends JSONTokener {
3636
/** The table of entity values. It initially contains Character values for
3737
* amp, apos, gt, lt, quot.
3838
*/
39-
public static final java.util.HashMap<String, Character> entity;
39+
public static final java.util.LinkedHashMap<String, Character> entity;
4040

4141
static {
42-
entity = new java.util.HashMap<String, Character>(8);
42+
entity = new java.util.LinkedHashMap<String, Character>(8);
4343
entity.put("amp", XML.AMP);
4444
entity.put("apos", XML.APOS);
4545
entity.put("gt", XML.GT);

0 commit comments

Comments
 (0)