Skip to content

Commit 7701f21

Browse files
committed
Adding comments
1 parent ffd48af commit 7701f21

File tree

2 files changed

+59
-8
lines changed

2 files changed

+59
-8
lines changed

src/main/java/org/json/JSONArray.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,29 @@ public JSONArray(Collection<?> collection) {
152152
this(collection, 0, new JSONParserConfiguration());
153153
}
154154

155+
/**
156+
* Construct a JSONArray from a Collection.
157+
*
158+
* @param collection
159+
* A Collection.
160+
* @param jsonParserConfiguration
161+
* Configuration object for the JSON parser
162+
*/
155163
public JSONArray(Collection<?> collection, JSONParserConfiguration jsonParserConfiguration) {
156164
this(collection, 0, jsonParserConfiguration);
157165
}
158166

159-
protected JSONArray(Collection<?> collection, int recursionDepth, JSONParserConfiguration jsonParserConfiguration) {
167+
/**
168+
* Construct a JSONArray from a collection with recursion depth.
169+
*
170+
* @param collection
171+
* A Collection.
172+
* @param recursionDepth
173+
* Variable for tracking the count of nested object creations.
174+
* @param jsonParserConfiguration
175+
* Configuration object for the JSON parser
176+
*/
177+
JSONArray(Collection<?> collection, int recursionDepth, JSONParserConfiguration jsonParserConfiguration) {
160178
if (recursionDepth > jsonParserConfiguration.getMaxNestingDepth()) {
161179
throw new JSONException("JSONArray has reached recursion depth limit of " + jsonParserConfiguration.getMaxNestingDepth());
162180
}
@@ -1362,7 +1380,7 @@ public JSONArray put(int index, Map<?, ?> value) throws JSONException {
13621380
* @param value
13631381
* The Map value.
13641382
* @param jsonParserConfiguration
1365-
* Configuration for recursive depth
1383+
* Configuration object for the JSON parser
13661384
* @return
13671385
* @throws JSONException
13681386
* If the index is negative or if the value is an invalid
@@ -1811,8 +1829,7 @@ public boolean isEmpty() {
18111829
* {@code true} to call {@link JSONObject#wrap(Object)} for each item,
18121830
* {@code false} to add the items directly
18131831
* @param recursionDepth
1814-
* variable to keep the count of how nested the object creation is happening.
1815-
*
1832+
* Variable for tracking the count of nested object creations.
18161833
*/
18171834
private void addAll(Collection<?> collection, boolean wrap, int recursionDepth, JSONParserConfiguration jsonParserConfiguration) {
18181835
this.myArrayList.ensureCapacity(this.myArrayList.size() + collection.size());
@@ -1852,8 +1869,14 @@ private void addAll(Iterable<?> iter, boolean wrap) {
18521869
* Add an array's elements to the JSONArray.
18531870
*
18541871
* @param array
1872+
* Array. If the parameter passed is null, or not an array,
1873+
* JSONArray, Collection, or Iterable, an exception will be
1874+
* thrown.
18551875
* @param wrap
1876+
* {@code true} to call {@link JSONObject#wrap(Object)} for each item,
1877+
* {@code false} to add the items directly
18561878
* @throws JSONException
1879+
* If not an array or if an array value is non-finite number.
18571880
*/
18581881
private void addAll(Object array, boolean wrap) throws JSONException {
18591882
this.addAll(array, wrap, 0);
@@ -1867,7 +1890,10 @@ private void addAll(Object array, boolean wrap) throws JSONException {
18671890
* JSONArray, Collection, or Iterable, an exception will be
18681891
* thrown.
18691892
* @param wrap
1893+
* {@code true} to call {@link JSONObject#wrap(Object)} for each item,
1894+
* {@code false} to add the items directly
18701895
* @param recursionDepth
1896+
* Variable for tracking the count of nested object creations.
18711897
*/
18721898
private void addAll(Object array, boolean wrap, int recursionDepth) {
18731899
addAll(array, wrap, recursionDepth, new JSONParserConfiguration());
@@ -1883,8 +1909,8 @@ private void addAll(Object array, boolean wrap, int recursionDepth) {
18831909
* {@code true} to call {@link JSONObject#wrap(Object)} for each item,
18841910
* {@code false} to add the items directly
18851911
* @param recursionDepth
1886-
* Variable to keep the count of how nested the object creation is happening.
1887-
* @param recursionDepth
1912+
* Variable for tracking the count of nested object creations.
1913+
* @param jsonParserConfiguration
18881914
* Variable to pass parser custom configuration for json parsing.
18891915
* @throws JSONException
18901916
* If not an array or if an array value is non-finite number.

src/main/java/org/json/JSONObject.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,15 @@ public JSONObject(Map<?, ?> m) {
279279
this(m, 0, new JSONParserConfiguration());
280280
}
281281

282+
/**
283+
* Construct a JSONObject from a Map with custom json parse configurations.
284+
*
285+
* @param m
286+
* A map object that can be used to initialize the contents of
287+
* the JSONObject.
288+
* @param jsonParserConfiguration
289+
* Variable to pass parser custom configuration for json parsing.
290+
*/
282291
public JSONObject(Map<?, ?> m, JSONParserConfiguration jsonParserConfiguration) {
283292
this(m, 0, jsonParserConfiguration);
284293
}
@@ -287,7 +296,7 @@ public JSONObject(Map<?, ?> m, JSONParserConfiguration jsonParserConfiguration)
287296
* Construct a JSONObject from a map with recursion depth.
288297
*
289298
*/
290-
protected JSONObject(Map<?, ?> m, int recursionDepth, JSONParserConfiguration jsonParserConfiguration) {
299+
private JSONObject(Map<?, ?> m, int recursionDepth, JSONParserConfiguration jsonParserConfiguration) {
291300
if (recursionDepth > jsonParserConfiguration.getMaxNestingDepth()) {
292301
throw new JSONException("JSONObject has reached recursion depth limit of " + jsonParserConfiguration.getMaxNestingDepth());
293302
}
@@ -2581,7 +2590,23 @@ public static Object wrap(Object object) {
25812590
return wrap(object, null);
25822591
}
25832592

2584-
public static Object wrap(Object object, int recursionDepth, JSONParserConfiguration jsonParserConfiguration) {
2593+
/**
2594+
* Wrap an object, if necessary. If the object is <code>null</code>, return the NULL
2595+
* object. If it is an array or collection, wrap it in a JSONArray. If it is
2596+
* a map, wrap it in a JSONObject. If it is a standard property (Double,
2597+
* String, et al) then it is already wrapped. Otherwise, if it comes from
2598+
* one of the java packages, turn it into a string. And if it doesn't, try
2599+
* to wrap it in a JSONObject. If the wrapping fails, then null is returned.
2600+
*
2601+
* @param object
2602+
* The object to wrap
2603+
* @param recursionDepth
2604+
* Variable for tracking the count of nested object creations.
2605+
* @param jsonParserConfiguration
2606+
* Variable to pass parser custom configuration for json parsing.
2607+
* @return The wrapped value
2608+
*/
2609+
static Object wrap(Object object, int recursionDepth, JSONParserConfiguration jsonParserConfiguration) {
25852610
return wrap(object, null, recursionDepth, jsonParserConfiguration);
25862611
}
25872612

0 commit comments

Comments
 (0)