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

DRAFT: (JSONArray).toList() breaks format of entries #810

Closed
wants to merge 2 commits into from
Closed
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
98 changes: 97 additions & 1 deletion src/main/java/org/json/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;


Expand Down Expand Up @@ -61,7 +62,7 @@
* @author JSON.org
* @version 2016-08/15
*/
public class JSONArray implements Iterable<Object> {
public class JSONArray implements List<Object> {

/**
* The arrayList where the JSONArray's properties are kept.
Expand Down Expand Up @@ -229,6 +230,54 @@ public Iterator<Object> iterator() {
return this.myArrayList.iterator();
}

@Override
public Object[] toArray() {
return myArrayList.toArray();
}

@Override
public <T> 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.
*
Expand All @@ -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.
Expand Down Expand Up @@ -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<Object> listIterator() {
return myArrayList.listIterator();
}

@Override
public ListIterator<Object> listIterator(int index) {
return myArrayList.listIterator(index);
}

@Override
public List<Object> subList(int from, int to) {
return myArrayList.subList(from, to);
}

/**
* Determine if two JSONArrays are similar.
* They must contain similar sequences.
Expand Down Expand Up @@ -1762,6 +1848,11 @@ public List<Object> toList() {
return results;
}

@Override
public int size() {
return myArrayList.size();
}

/**
* Check if JSONArray is empty.
*
Expand All @@ -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.
*
Expand Down
Loading