fix code and add sh

This commit is contained in:
Looly
2020-03-31 11:06:39 +08:00
parent 174d80e865
commit ccccbf67aa
8 changed files with 101 additions and 90 deletions

View File

@@ -252,8 +252,21 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
*
* @param value 值,可以是: Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the JSONNull.NULL。
* @return this.
* @see #set(Object)
*/
public JSONArray put(Object value) {
return set(value);
}
/**
* Append an object value. This increases the array's length by one. <br>
* 加入元素,数组长度+1等同于 {@link JSONArray#add(Object)}
*
* @param value 值,可以是: Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the JSONNull.NULL。
* @return this.
* @since 5.2.5
*/
public JSONArray set(Object value) {
this.add(value);
return this;
}
@@ -284,7 +297,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
}
JSONObject jo = new JSONObject();
for (int i = 0; i < names.size(); i += 1) {
jo.put(names.getStr(i), this.getObj(i));
jo.set(names.getStr(i), this.getObj(i));
}
return jo;
}
@@ -440,7 +453,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
while (index != this.size()) {
this.add(JSONNull.NULL);
}
this.put(element);
this.set(element);
}
}

View File

@@ -279,7 +279,7 @@ public class JSONObject implements JSON, JSONGetter<String>, Map<String, Object>
for (String name : names) {
value = this.get(name);
if (null != value) {
ja.put(value);
ja.set(value);
}
}
return ja;
@@ -332,14 +332,16 @@ public class JSONObject implements JSON, JSONGetter<String>, Map<String, Object>
}
/**
* PUT 键值对到JSONObject中如果值为<code>null</code>,将此键移除
* PUT 键值对到JSONObject中在忽略null模式下如果值为<code>null</code>,将此键移除
*
* @param key 键
* @param value 值对象. 可以是以下类型: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, or the JSONNull.NULL.
* @return this.
* @throws JSONException 值是无穷数字抛出此异常
* @deprecated 此方法存在歧义原Map接口返回的是之前的值重写后返回this了未来版本此方法会修改请使用{@link #set(String, Object)}
*/
@Override
@Deprecated
public JSONObject put(String key, Object value) throws JSONException {
if (null == key) {
return this;
@@ -356,6 +358,19 @@ public class JSONObject implements JSON, JSONGetter<String>, Map<String, Object>
return this;
}
/**
* 设置键值对到JSONObject中在忽略null模式下如果值为<code>null</code>,将此键移除
*
* @param key 键
* @param value 值对象. 可以是以下类型: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, or the JSONNull.NULL.
* @return this.
* @throws JSONException 值是无穷数字抛出此异常
*/
public JSONObject set(String key, Object value) throws JSONException {
put(key, value);
return this;
}
/**
* 一次性Put 键值对如果key已经存在抛出异常如果键值中有null值忽略
*
@@ -365,7 +380,7 @@ public class JSONObject implements JSON, JSONGetter<String>, Map<String, Object>
* @throws JSONException 值是无穷数字、键重复抛出异常
*/
public JSONObject putOnce(String key, Object value) throws JSONException {
if (key != null && value != null) {
if (key != null) {
if (rawHashMap.containsKey(key)) {
throw new JSONException("Duplicate key \"{}\"", key);
}
@@ -409,11 +424,11 @@ public class JSONObject implements JSON, JSONGetter<String>, Map<String, Object>
InternalJSONUtil.testValidity(value);
Object object = this.getObj(key);
if (object == null) {
this.put(key, value instanceof JSONArray ? new JSONArray().put(value) : value);
this.put(key, value instanceof JSONArray ? new JSONArray().set(value) : value);
} else if (object instanceof JSONArray) {
((JSONArray) object).put(value);
((JSONArray) object).set(value);
} else {
this.put(key, new JSONArray().put(object).put(value));
this.set(key, new JSONArray().set(object).set(value));
}
return this;
}
@@ -430,9 +445,9 @@ public class JSONObject implements JSON, JSONGetter<String>, Map<String, Object>
InternalJSONUtil.testValidity(value);
Object object = this.getObj(key);
if (object == null) {
this.put(key, new JSONArray().put(value));
this.set(key, new JSONArray().set(value));
} else if (object instanceof JSONArray) {
this.put(key, ((JSONArray) object).put(value));
this.set(key, ((JSONArray) object).set(value));
} else {
throw new JSONException("JSONObject [" + key + "] is not a JSONArray.");
}

View File

@@ -10,10 +10,10 @@ import java.util.Iterator;
*/
public class JSONObjectIter implements Iterable<JSONObject> {
Iterator<Object> iter;
Iterator<Object> iterator;
public JSONObjectIter(Iterator<Object> iter) {
this.iter = iter;
public JSONObjectIter(Iterator<Object> iterator) {
this.iterator = iterator;
}
@Override
@@ -22,17 +22,17 @@ public class JSONObjectIter implements Iterable<JSONObject> {
@Override
public boolean hasNext() {
return iter.hasNext();
return iterator.hasNext();
}
@Override
public JSONObject next() {
return (JSONObject) iter.next();
return (JSONObject) iterator.next();
}
@Override
public void remove() {
iter.remove();
iterator.remove();
}
};
}