Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates javadoc to match actual exceptions thrown. #405

Merged
merged 1 commit into from
Mar 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 72 additions & 42 deletions JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.List;
import java.util.Map;


/**
* A JSONArray is an ordered sequence of values. Its external text form is a
* string wrapped in square brackets with commas separating the values. The
Expand Down Expand Up @@ -182,7 +183,7 @@ public JSONArray(Collection<?> collection) {
* Construct a JSONArray from an array
*
* @throws JSONException
* If not an array.
* If not an array or if an array value is non-finite number.
*/
public JSONArray(Object array) throws JSONException {
this();
Expand Down Expand Up @@ -465,11 +466,11 @@ public String getString(int index) throws JSONException {
}

/**
* Determine if the value is null.
* Determine if the value is <code>null</code>.
*
* @param index
* The index must be between 0 and length() - 1.
* @return true if the value at the index is null, or if there is no value.
* @return true if the value at the index is <code>null</code>, or if there is no value.
*/
public boolean isNull(int index) {
return JSONObject.NULL.equals(this.opt(index));
Expand Down Expand Up @@ -953,8 +954,7 @@ public String optString(int index, String defaultValue) {
* @return this.
*/
public JSONArray put(boolean value) {
this.put(value ? Boolean.TRUE : Boolean.FALSE);
return this;
return this.put(value ? Boolean.TRUE : Boolean.FALSE);
}

/**
Expand All @@ -964,26 +964,37 @@ public JSONArray put(boolean value) {
* @param value
* A Collection value.
* @return this.
* @throws JSONException
* If the value is non-finite number.
*/
public JSONArray put(Collection<?> value) {
this.put(new JSONArray(value));
return this;
return this.put(new JSONArray(value));
}

/**
* Append a double value. This increases the array's length by one.
*
* @param value
* A double value.
* @return this.
* @throws JSONException
* if the value is not finite.
* @return this.
*/
public JSONArray put(double value) throws JSONException {
Double d = new Double(value);
JSONObject.testValidity(d);
this.put(d);
return this;
return this.put(Double.valueOf(value));
}

/**
* Append a float value. This increases the array's length by one.
*
* @param value
* A float value.
* @return this.
* @throws JSONException
* if the value is not finite.
*/
public JSONArray put(float value) throws JSONException {
return this.put(Float.valueOf(value));
}

/**
Expand All @@ -994,8 +1005,7 @@ public JSONArray put(double value) throws JSONException {
* @return this.
*/
public JSONArray put(int value) {
this.put(new Integer(value));
return this;
return this.put(Integer.valueOf(value));
}

/**
Expand All @@ -1006,8 +1016,7 @@ public JSONArray put(int value) {
* @return this.
*/
public JSONArray put(long value) {
this.put(new Long(value));
return this;
return this.put(Long.valueOf(value));
}

/**
Expand All @@ -1017,10 +1026,13 @@ public JSONArray put(long value) {
* @param value
* A Map value.
* @return this.
* @throws JSONException
* If a value in the map is non-finite number.
* @throws NullPointerException
* If a key in the map is <code>null</code>
*/
public JSONArray put(Map<?, ?> value) {
this.put(new JSONObject(value));
return this;
return this.put(new JSONObject(value));
}

/**
Expand All @@ -1031,8 +1043,11 @@ public JSONArray put(Map<?, ?> value) {
* Integer, JSONArray, JSONObject, Long, or String, or the
* JSONObject.NULL object.
* @return this.
* @throws JSONException
* If the value is non-finite number.
*/
public JSONArray put(Object value) {
JSONObject.testValidity(value);
this.myArrayList.add(value);
return this;
}
Expand All @@ -1051,8 +1066,7 @@ public JSONArray put(Object value) {
* If the index is negative.
*/
public JSONArray put(int index, boolean value) throws JSONException {
this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
return this;
return this.put(index, value ? Boolean.TRUE : Boolean.FALSE);
}

/**
Expand All @@ -1065,11 +1079,10 @@ public JSONArray put(int index, boolean value) throws JSONException {
* A Collection value.
* @return this.
* @throws JSONException
* If the index is negative or if the value is not finite.
* If the index is negative or if the value is non-finite.
*/
public JSONArray put(int index, Collection<?> value) throws JSONException {
this.put(index, new JSONArray(value));
return this;
return this.put(index, new JSONArray(value));
}

/**
Expand All @@ -1083,11 +1096,27 @@ public JSONArray put(int index, Collection<?> value) throws JSONException {
* A double value.
* @return this.
* @throws JSONException
* If the index is negative or if the value is not finite.
* If the index is negative or if the value is non-finite.
*/
public JSONArray put(int index, double value) throws JSONException {
this.put(index, new Double(value));
return this;
return this.put(index, Double.valueOf(value));
}

/**
* Put or replace a float value. If the index is greater than the length of
* the JSONArray, then null elements will be added as necessary to pad it
* out.
*
* @param index
* The subscript.
* @param value
* A float value.
* @return this.
* @throws JSONException
* If the index is negative or if the value is non-finite.
*/
public JSONArray put(int index, float value) throws JSONException {
return this.put(index, Float.valueOf(value));
}

/**
Expand All @@ -1104,8 +1133,7 @@ public JSONArray put(int index, double value) throws JSONException {
* If the index is negative.
*/
public JSONArray put(int index, int value) throws JSONException {
this.put(index, new Integer(value));
return this;
return this.put(index, Integer.valueOf(value));
}

/**
Expand All @@ -1122,8 +1150,7 @@ public JSONArray put(int index, int value) throws JSONException {
* If the index is negative.
*/
public JSONArray put(int index, long value) throws JSONException {
this.put(index, new Long(value));
return this;
return this.put(index, Long.valueOf(value));
}

/**
Expand All @@ -1138,6 +1165,8 @@ public JSONArray put(int index, long value) throws JSONException {
* @throws JSONException
* If the index is negative or if the the value is an invalid
* number.
* @throws NullPointerException
* If a key in the map is <code>null</code>
*/
public JSONArray put(int index, Map<?, ?> value) throws JSONException {
this.put(index, new JSONObject(value));
Expand All @@ -1161,25 +1190,26 @@ public JSONArray put(int index, Map<?, ?> value) throws JSONException {
* number.
*/
public JSONArray put(int index, Object value) throws JSONException {
JSONObject.testValidity(value);
if (index < 0) {
throw new JSONException("JSONArray[" + index + "] not found.");
}
if (index < this.length()) {
JSONObject.testValidity(value);
this.myArrayList.set(index, value);
} else if(index == this.length()){
return this;
}
if(index == this.length()){
// simple append
this.put(value);
} else {
// if we are inserting past the length, we want to grow the array all at once
// instead of incrementally.
this.myArrayList.ensureCapacity(index + 1);
while (index != this.length()) {
this.put(JSONObject.NULL);
}
this.put(value);
return this.put(value);
}
return this;
// if we are inserting past the length, we want to grow the array all at once
// instead of incrementally.
this.myArrayList.ensureCapacity(index + 1);
while (index != this.length()) {
// we don't need to test validity of NULL objects
this.myArrayList.add(JSONObject.NULL);
}
return this.put(value);
}

/**
Expand Down
Loading