public class JSArray extends JSNode implements java.lang.Iterable
JSArray extends JSNode and JSNode implements Map so it is impossible for JSArray to implement List but that is practically what is happening.
This builds on JSNode but instead of string based keys, the keys are integer index positions in an underlying List.
JSNode| Modifier and Type | Field and Description |
|---|---|
protected java.util.List |
objects
The objects stored in this JSArray.
|
| Constructor and Description |
|---|
JSArray(java.lang.Object... objects) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
java.lang.Object value)
Overloading of
set(int, Object) |
void |
add(java.lang.Object value)
Adds
object to the end of objects |
void |
addAll(JSArray array)
Adds all elements from
array to the end of objects |
JSArray |
asArray()
Similar to #asList() but instead of returning a List, it returns a this JSNode
as the only item in a JSArray.
|
java.util.List |
asList()
Returns this object as the only element in a list.
|
java.util.Map |
asMap() |
void |
clear()
Removes all properties
|
boolean |
contains(java.lang.Object object) |
java.lang.Object |
get(int index)
Gets the object at
index and will not throw ArrayIndexOutOfBoundsException |
java.lang.Object |
get(java.lang.Object index)
Override of JSNode.get(Object) to parse
index as an Integer and pull from objects instead of JSNode.properties |
JSArray |
getArray(int index)
Convenience overloading of
get(Object) |
boolean |
getBoolean(int index)
Convenience overloading of
get(int) |
double |
getDouble(int index)
Convenience overloading of
get(Object) |
int |
getInt(int index)
Convenience overloading of
get(Object) |
JSNode |
getNode(int index)
Convenience overloading of
get(int) |
java.lang.String |
getString(int index)
Convenience overloading of
get(Object) |
boolean |
isArray()
Easy alternative to 'instanceof' to differentiate JSNode from JSArray (which subclasses JSNode).
|
boolean |
isEmpty() |
java.util.Iterator |
iterator() |
java.util.Set<java.lang.String> |
keySet() |
int |
length() |
java.lang.Object |
put(int index,
java.lang.Object value)
Overloading of
put(String, Object) for completion, really just calls set(int, Object) |
java.lang.Object |
put(java.lang.String index,
java.lang.Object value)
Override of JSNode.put(String, Object) to parse
index as an Integer and store the result in objects instead of JSNode.properties |
java.lang.Object |
remove(int index)
Removes column
index if it exists. |
java.lang.Object |
remove(java.lang.Object index)
Override of JSNode.remove(Object) to parse
index as an Integer and remove the column from objects instead of removing the key from JSNode.properties |
java.lang.Object |
set(int index,
java.lang.Object value)
Sets
objects[index] to value expanding the size of objects as much as is required. |
int |
size() |
java.util.Collection |
values() |
asNodeList, containsKey, containsValue, copy, diff, entrySet, find, findAll, findAll, findAllNodes, findArray, findBoolean, findDouble, findInt, findLong, findNode, findString, getArray, getBoolean, getDouble, getInt, getLong, getNode, getString, hasProperty, parseJson, parseJsonArray, parseJsonNode, patch, putAll, putFirst, removeAll, sortKeys, stream, streamAll, toString, toString, toString, withprotected java.util.List objects
This replaces the use of the JSNode.properties map from the superclass.
public boolean isArray()
JSNodeisArray in class JSNodeJSNode.isArray()public java.lang.Object put(java.lang.String index,
java.lang.Object value)
index as an Integer and store the result in objects instead of JSNode.properties
Put/set/add are basically synonyms.
put in interface java.util.Map<java.lang.String,java.lang.Object>put in class JSNodeindexset(int, Object)public java.lang.Object put(int index,
java.lang.Object value)
put(String, Object) for completion, really just calls set(int, Object)
Put/set/add are basically synonyms.
index - the zero based property index to storevalue - a JSNode, JSArray, or compatible Java typeindexset(int, Object)public java.lang.Object set(int index,
java.lang.Object value)
throws java.lang.ArrayIndexOutOfBoundsException
objects[index] to value expanding the size of objects as much as is required.
Put/set/add are basically synonyms.
index - the zero based property index to storevalue - a JSNode, JSArray, or compatible Java typeindex if it existsjava.lang.ArrayIndexOutOfBoundsException - only if index is @lt; 0public void add(int index,
java.lang.Object value)
set(int, Object)index - the zero based property index to storevalue - a JSNode, JSArray, or compatible Java typepublic void add(java.lang.Object value)
object to the end of objectsvalue - a JSNode, JSArray, or compatible Java typepublic void addAll(JSArray array)
array to the end of objectsarray - an array of elements to addpublic java.lang.Object remove(java.lang.Object index)
index as an Integer and remove the column from objects instead of removing the key from JSNode.propertiesremove in interface java.util.Map<java.lang.String,java.lang.Object>remove in class JSNodeindex - a value that should parse to an integerindex if it exitsremove(int)public java.lang.Object remove(int index)
index if it exists.
Will not throw ArrayIndexOutOfBoundsException
index - the element/column to remove from objectsindex if it exitspublic java.lang.Object get(java.lang.Object index)
index as an Integer and pull from objects instead of JSNode.propertiespublic java.lang.Object get(int index)
index and will not throw ArrayIndexOutOfBoundsExceptionindex - the zero based property index to getindex if it exists else, nullpublic JSNode getNode(int index) throws java.lang.ClassCastException
get(int)index - the zero based property index to getindex cast to a JSNode if exists else nulljava.lang.ClassCastException - if the object found is not a JSNodeget(Object)public JSArray getArray(int index)
get(Object)index - the zero based property index to getindex cast to a JSArray if exists else nulljava.lang.ClassCastException - if the object found is not a JSArrayget(Object)public java.lang.String getString(int index)
get(Object)index - the zero based property index to getname stringified if it exists else nullget(Object)public int getInt(int index)
get(Object)index - the zero based property index to getindex stringified and parsed as an int if it exists else -1get(Object)public double getDouble(int index)
get(Object)index - the zero based property index to getindex stringified and parsed as a double if it exists else -1get(Object)public boolean getBoolean(int index)
get(int)index - the zero based property index to getindex stringified and parsed as a boolean if it exists else falseget(Object)public java.util.Set<java.lang.String> keySet()
public java.util.List asList()
JSNodeJSArray overrides this method to return all of its elements in a list.
This method is designed to make it super easy to iterate over all property values or array elements without having to cast or consider differences between JSNode and JSArray.
For example:
JSNode node = response.getJson();//don't know if this is a JSNode or JSArray
for(Object value : node.asList())
{
//do something;
}
asList in class JSNodeasList(),
JSNode.asNodeList()public JSArray asArray()
JSNodeJSArray overrides this method to simply return 'this'.
asArray in class JSNodeJSNode.asList(),
JSNode.asNodeList(),
asArray()public java.util.Map asMap()
public boolean contains(java.lang.Object object)
public boolean isEmpty()
public void clear()
JSNodepublic int size()
public int length()
public java.util.Iterator iterator()
iterator in interface java.lang.IterableCopyright © 2021 Rocket Partners, LLC. All rights reserved.