mirror of
https://github.com/stleary/JSON-java.git
synced 2026-01-24 00:03:17 -05:00
Development for stleary#516 completed with rebased repository
- Introduced JSONObject(int) constructor.
- int > Initial capacity of the underlying data structure
- Test for new introduced JSONArray(int) constructor.
1. Checked with input parameter: 0
2. Checked with input parameter: positive number
3. Checked with positive number input parameter and compared length
4. If input parameter is negative number JSONException is thrown:
JSONArray initial capacity cannot be negative.
This commit is contained in:
@@ -205,6 +205,22 @@ public class JSONArray implements Iterable<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a JSONArray with the specified initial capacity.
|
||||
*
|
||||
* @param initialCapacity
|
||||
* the initial capacity of the JSONArray.
|
||||
* @throws JSONException
|
||||
* If the initial capacity is negative.
|
||||
*/
|
||||
public JSONArray(int initialCapacity) throws JSONException {
|
||||
if (initialCapacity < 0) {
|
||||
throw new JSONException(
|
||||
"JSONArray initial capacity cannot be negative.");
|
||||
}
|
||||
this.myArrayList = new ArrayList<Object>(initialCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Object> iterator() {
|
||||
return this.myArrayList.iterator();
|
||||
|
||||
Reference in New Issue
Block a user