Files
lang
modules
org
config.yml
plugin.yml
Code
58 4,561
org/json/JSONArray.java
package org.json;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class JSONArray implements Iterable<Object> {
private final ArrayList<Object> myArrayList;
public JSONArray() {
this.myArrayList = new ArrayList();
}
public JSONArray(JSONTokener x) throws JSONException {
this();
if (x.nextClean() != '[') {
throw x.syntaxError("A JSONArray text must start with '['");
} else {
char nextChar = x.nextClean();
if (nextChar == 0) {
throw x.syntaxError("Expected a ',' or ']'");
} else if (nextChar != ']') {
x.back();
while(true) {
if (x.nextClean() == ',') {
x.back();
this.myArrayList.add(JSONObject.NULL);
} else {
x.back();
this.myArrayList.add(x.nextValue());
}
switch (x.nextClean()) {
case '\u0000':
throw x.syntaxError("Expected a ',' or ']'");
case ',':
nextChar = x.nextClean();
if (nextChar == 0) {
throw x.syntaxError("Expected a ',' or ']'");
}
if (nextChar == ']') {
return;
}
x.back();
break;
case ']':
return;
default:
throw x.syntaxError("Expected a ',' or ']'");
}
}
}
}
}
public JSONArray(String source) throws JSONException {
this(new JSONTokener(source));
}
public JSONArray(Collection<?> collection) {
if (collection == null) {
this.myArrayList = new ArrayList();
} else {
this.myArrayList = new ArrayList(collection.size());
this.addAll(collection, true);
}
}
public JSONArray(Iterable<?> iter) {
this();
if (iter != null) {
this.addAll(iter, true);
}
}
public JSONArray(JSONArray array) {
if (array == null) {
this.myArrayList = new ArrayList();
} else {
this.myArrayList = new ArrayList(array.myArrayList);
}
}
public JSONArray(Object array) throws JSONException {
this();
if (!array.getClass().isArray()) {
throw new JSONException("JSONArray initial value should be a string or collection or array.");
} else {
this.addAll(array, true);
}
}
public JSONArray(int initialCapacity) throws JSONException {
if (initialCapacity < 0) {
throw new JSONException("JSONArray initial capacity cannot be negative.");
} else {
this.myArrayList = new ArrayList(initialCapacity);
}
}
public Iterator<Object> iterator() {
return this.myArrayList.iterator();
}
public Object get(int index) throws JSONException {
Object object = this.opt(index);
if (object == null) {
throw new JSONException("JSONArray[" + index + "] not found.");
} else {
return object;
}
}
public boolean getBoolean(int index) throws JSONException {
Object object = this.get(index);
if (!object.equals(Boolean.FALSE) && (!(object instanceof String) || !((String)object).equalsIgnoreCase("false"))) {
if (!object.equals(Boolean.TRUE) && (!(object instanceof String) || !((String)object).equalsIgnoreCase("true"))) {
throw wrongValueFormatException(index, "boolean", object, (Throwable)null);
} else {
return true;
}
} else {
return false;
}
}
public double getDouble(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof Number) {
return ((Number)object).doubleValue();
} else {
try {
return Double.parseDouble(object.toString());
} catch (Exception e) {
throw wrongValueFormatException(index, "double", object, e);
}
}
}
public float getFloat(int index) throws JSONException {
Object object = this.get(index);
if (object instanceof Number) {
return ((Number)object).floatValue();
} else {
try {
return Float.parseFloat(object.toString());
} catch (Exception e) {
throw wrongValueFormatException(index, "float", object, e);
}
}
}
public Number getNumber(int index) throws JSONException {
Object object = this.get(index);
try {
return object instanceof Number ? (Number)object : JSONObject.stringToNumber(object.toString());
} catch (Exception e) {
throw wrongValueFormatException(index, "number", object, e);
}
}
public <E extends Enum<E>> E getEnum(Class<E> clazz, int index) throws JSONException {
E val = this.optEnum(clazz, index);
if (val == null) {
throw wrongValueFormatException(index, "enum of type " + JSONObject.quote(clazz.getSimpleName()), this.opt(index), (Throwable)null);
} else {
return val;
}
}
public BigDecimal getBigDecimal(int index) throws JSONException {
Object object = this.get(index);
BigDecimal val = JSONObject.objectToBigDecimal(object, (BigDecimal)null);
if (val == null) {
throw wrongValueFormatException(index, "BigDecimal", object, (Throwable)null);
} else {
return val;
}
}
public BigInteger getBigInteger(int index) throws JSONException {
Object object = this.get(index);
BigInteger val = JSONObject.objectToBigInteger(object, (BigInteger)null);
if (val == null) {
throw wrongValueFormatException(index, "BigInteger", object, (Throwable)null);
} else {