diff --git a/src/main/java/org/json/JSONArray.java b/src/main/java/org/json/JSONArray.java index b0c912d1f..0729d7d10 100644 --- a/src/main/java/org/json/JSONArray.java +++ b/src/main/java/org/json/JSONArray.java @@ -14,6 +14,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.ListIterator; import java.util.Map; @@ -61,7 +62,7 @@ * @author JSON.org * @version 2016-08/15 */ -public class JSONArray implements Iterable { +public class JSONArray implements List { /** * The arrayList where the JSONArray's properties are kept. @@ -229,6 +230,54 @@ public Iterator iterator() { return this.myArrayList.iterator(); } + @Override + public Object[] toArray() { + return myArrayList.toArray(); + } + + @Override + public T[] toArray(T[] array) { + return myArrayList.toArray(array); + } + + @Override + public boolean add(Object object) { + JSONObject.testValidity(object); + return myArrayList.add(object); + } + + @Override + public boolean remove(Object object) { + return myArrayList.remove(object); + } + + @Override + public boolean containsAll(Collection collection) { + return myArrayList.containsAll(collection); + } + + @Override + public boolean addAll(Collection collection) { + JSONObject.testValidity(collection); + return myArrayList.addAll(collection); + } + + @Override + public boolean addAll(int index, Collection collection) { + JSONObject.testValidity(collection); + return myArrayList.addAll(index, collection); + } + + @Override + public boolean removeAll(Collection collection) { + return myArrayList.removeAll(collection); + } + + @Override + public boolean retainAll(Collection collection) { + return myArrayList.retainAll(collection); + } + /** * Get the object value associated with an index. * @@ -246,6 +295,18 @@ public Object get(int index) throws JSONException { return object; } + @Override + public Object set(int index, Object object) { + JSONObject.testValidity(object); + return myArrayList.set(index, object); + } + + @Override + public void add(int index, Object object) { + JSONObject.testValidity(object); + myArrayList.add(index, object); + } + /** * Get the boolean value associated with an index. The string values "true" * and "false" are converted to boolean. @@ -1525,6 +1586,31 @@ public Object remove(int index) { : null; } + @Override + public int indexOf(Object object) { + return myArrayList.indexOf(object); + } + + @Override + public int lastIndexOf(Object object) { + return myArrayList.lastIndexOf(object); + } + + @Override + public ListIterator listIterator() { + return myArrayList.listIterator(); + } + + @Override + public ListIterator listIterator(int index) { + return myArrayList.listIterator(index); + } + + @Override + public List subList(int from, int to) { + return myArrayList.subList(from, to); + } + /** * Determine if two JSONArrays are similar. * They must contain similar sequences. @@ -1762,6 +1848,11 @@ public List toList() { return results; } + @Override + public int size() { + return myArrayList.size(); + } + /** * Check if JSONArray is empty. * @@ -1771,6 +1862,11 @@ public boolean isEmpty() { return this.myArrayList.isEmpty(); } + @Override + public boolean contains(Object object) { + return myArrayList.contains(object); + } + /** * Add a collection's elements to the JSONArray. *