From 6fda2ac9af45b03a19aed7cd986bea10459a4835 Mon Sep 17 00:00:00 2001 From: Erkan Erdem Date: Mon, 10 Jul 2017 10:46:22 +0300 Subject: [PATCH] Changed all HashMap to LinkedHashMap --- JSONObject.java | 21 +++++++-------------- XMLTokener.java | 4 ++-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/JSONObject.java b/JSONObject.java index 8ad7864df..76407b878 100644 --- a/JSONObject.java +++ b/JSONObject.java @@ -32,15 +32,8 @@ of this software and associated documentation files (the "Software"), to deal import java.lang.reflect.Modifier; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; -import java.util.Map; +import java.util.*; import java.util.Map.Entry; -import java.util.ResourceBundle; -import java.util.Set; /** * A JSONObject is an unordered collection of name/value pairs. Its external @@ -164,13 +157,13 @@ public String toString() { * Construct an empty JSONObject. */ public JSONObject() { - // HashMap is used on purpose to ensure that elements are unordered by + // LinkedHashMap is used on purpose to ensure that elements are unordered by // the specification. // JSON tends to be a portable transfer format to allows the container // implementations to rearrange their items for a faster element // retrieval based on associative access. // Therefore, an implementation mustn't rely on the order of the item. - this.map = new HashMap(); + this.map = new LinkedHashMap(); } /** @@ -257,9 +250,9 @@ public JSONObject(JSONTokener x) throws JSONException { */ public JSONObject(Map m) { if (m == null) { - this.map = new HashMap(); + this.map = new LinkedHashMap(); } else { - this.map = new HashMap(m.size()); + this.map = new LinkedHashMap(m.size()); for (final Entry e : m.entrySet()) { final Object value = e.getValue(); if (value != null) { @@ -388,7 +381,7 @@ public JSONObject(String baseName, Locale locale) throws JSONException { * @param initialCapacity initial capacity of the internal map. */ protected JSONObject(int initialCapacity){ - this.map = new HashMap(initialCapacity); + this.map = new LinkedHashMap(initialCapacity); } /** @@ -2315,7 +2308,7 @@ public Writer write(Writer writer, int indentFactor, int indent) * @return a java.util.Map containing the entries of this object */ public Map toMap() { - Map results = new HashMap(); + Map results = new LinkedHashMap(); for (Entry entry : this.entrySet()) { Object value; if (entry.getValue() == null || NULL.equals(entry.getValue())) { diff --git a/XMLTokener.java b/XMLTokener.java index 1c5f2b59d..80c3d2551 100644 --- a/XMLTokener.java +++ b/XMLTokener.java @@ -36,10 +36,10 @@ public class XMLTokener extends JSONTokener { /** The table of entity values. It initially contains Character values for * amp, apos, gt, lt, quot. */ - public static final java.util.HashMap entity; + public static final java.util.LinkedHashMap entity; static { - entity = new java.util.HashMap(8); + entity = new java.util.LinkedHashMap(8); entity.put("amp", XML.AMP); entity.put("apos", XML.APOS); entity.put("gt", XML.GT);