io.inversion.json.JSList Maven / Gradle / Ivy
The newest version!
package io.inversion.json;
import io.inversion.utils.Utils;
import java.util.*;
public class JSList extends ArrayList implements JSNode {
JSListKeys keySet = null;
public JSList(Object... objects) {
if (objects != null && objects.length == 1 && objects[0].getClass().isArray()) {
objects = (Object[]) objects[0];
} else if (objects != null && objects.length == 1 && java.util.Collection.class.isAssignableFrom(objects[0].getClass())) {
objects = ((java.util.Collection) objects[0]).toArray();
}
for (int i = 0; objects != null && i < objects.length; i++)
add(objects[i]);
}
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
//-- JSNode Implementation
@Override
public Object get(Object key) {
int idx = Utils.atoi(key);
if (idx > -1 && idx < size())
return get(idx);
return null;
}
@Override
public Object put(Object key, Object value) {
int idx = Utils.atoi(key);
return set(idx, value);
}
@Override
public Object removeProp(Object key) {
int idx = Utils.atoi(key);
if (idx > -1 && idx < size()) {
Object oldVal = get(idx);
remove(idx);
return oldVal;
}
return null;
}
/**
* Returns this JSList
*/
@Override
public List