mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
changed Map<String, ?> method parameters to Map<?,?>
changed Iterator to foreach loop in JSONArray ctor JSONArray(Collection<?> collection) and JSONObject ctor JSONObject(Map<?,?> map)
This commit is contained in:
parent
409eb9f292
commit
25b5aa7ef2
2 changed files with 13 additions and 18 deletions
|
@ -154,10 +154,9 @@ public class JSONArray implements Iterable<Object> {
|
||||||
public JSONArray(Collection<?> collection) {
|
public JSONArray(Collection<?> collection) {
|
||||||
this.myArrayList = new ArrayList<Object>();
|
this.myArrayList = new ArrayList<Object>();
|
||||||
if (collection != null) {
|
if (collection != null) {
|
||||||
Iterator<?> iter = collection.iterator();
|
for (Object o: collection){
|
||||||
while (iter.hasNext()) {
|
this.myArrayList.add(JSONObject.wrap(o));
|
||||||
this.myArrayList.add(JSONObject.wrap(iter.next()));
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -799,7 +798,7 @@ public class JSONArray implements Iterable<Object> {
|
||||||
* A Map value.
|
* A Map value.
|
||||||
* @return this.
|
* @return this.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(Map<String, ?> value) {
|
public JSONArray put(Map<?, ?> value) {
|
||||||
this.put(new JSONObject(value));
|
this.put(new JSONObject(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -920,7 +919,7 @@ public class JSONArray implements Iterable<Object> {
|
||||||
* If the index is negative or if the the value is an invalid
|
* If the index is negative or if the the value is an invalid
|
||||||
* number.
|
* number.
|
||||||
*/
|
*/
|
||||||
public JSONArray put(int index, Map<String, ?> value) throws JSONException {
|
public JSONArray put(int index, Map<?, ?> value) throws JSONException {
|
||||||
this.put(index, new JSONObject(value));
|
this.put(index, new JSONObject(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,17 +243,13 @@ public class JSONObject {
|
||||||
* the JSONObject.
|
* the JSONObject.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public JSONObject(Map<String, ?> map) {
|
public JSONObject(Map<?, ?> map) {
|
||||||
this.map = new HashMap<String, Object>();
|
this.map = new HashMap<String, Object>();
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
Set<?> eSet = map.entrySet();
|
for (final Entry<?, ?> e : map.entrySet()) {
|
||||||
@SuppressWarnings("unchecked")
|
final Object value = e.getValue();
|
||||||
Iterator<Entry<String, ?>> i = (Iterator<Entry<String, ?>>) eSet.iterator();
|
|
||||||
while (i.hasNext()) {
|
|
||||||
Entry<String, ?> entry = i.next();
|
|
||||||
Object value = entry.getValue();
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
this.map.put(entry.getKey(), wrap(value));
|
this.map.put(String.valueOf(e.getKey()), wrap(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1270,7 +1266,7 @@ public class JSONObject {
|
||||||
* @return this.
|
* @return this.
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
public JSONObject put(String key, Map<String, ?> value) throws JSONException {
|
public JSONObject put(String key, Map<?, ?> value) throws JSONException {
|
||||||
this.put(key, new JSONObject(value));
|
this.put(key, new JSONObject(value));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1666,7 +1662,7 @@ public class JSONObject {
|
||||||
}
|
}
|
||||||
if (value instanceof Map) {
|
if (value instanceof Map) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, ?> map = (Map<String, ?>) value;
|
Map<?, ?> map = (Map<?, ?>) value;
|
||||||
return new JSONObject(map).toString();
|
return new JSONObject(map).toString();
|
||||||
}
|
}
|
||||||
if (value instanceof Collection) {
|
if (value instanceof Collection) {
|
||||||
|
@ -1718,7 +1714,7 @@ public class JSONObject {
|
||||||
}
|
}
|
||||||
if (object instanceof Map) {
|
if (object instanceof Map) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, ?> map = (Map<String, ?>) object;
|
Map<?, ?> map = (Map<?, ?>) object;
|
||||||
return new JSONObject(map);
|
return new JSONObject(map);
|
||||||
}
|
}
|
||||||
Package objectPackage = object.getClass().getPackage();
|
Package objectPackage = object.getClass().getPackage();
|
||||||
|
@ -1758,7 +1754,7 @@ public class JSONObject {
|
||||||
((JSONArray) value).write(writer, indentFactor, indent);
|
((JSONArray) value).write(writer, indentFactor, indent);
|
||||||
} else if (value instanceof Map) {
|
} else if (value instanceof Map) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, ?> map = (Map<String, ?>) value;
|
Map<?, ?> map = (Map<?, ?>) value;
|
||||||
new JSONObject(map).write(writer, indentFactor, indent);
|
new JSONObject(map).write(writer, indentFactor, indent);
|
||||||
} else if (value instanceof Collection) {
|
} else if (value instanceof Collection) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue