Class JSArray
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.
- See Also:
-
Nested Class Summary
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidOverloading ofset(int, Object)voidAddsobjectto the end ofobjectsvoidAdds all elements fromarrayto the end ofobjectsasArray()Similar to #asList() but instead of returning a List, it returns a this JSNode as the only item in a JSArray.asList()Returns this object as the only element in a list.asMap()voidclear()Removes all propertiesbooleanget(int index) Gets the object atindexand will not throw ArrayIndexOutOfBoundsExceptionOverride of JSNode.get(Object) to parseindexas an Integer and pull fromobjectsinstead of JSNode.propertiesgetArray(int index) Convenience overloading ofget(Object)booleangetBoolean(int index) Convenience overloading ofget(int)doublegetDouble(int index) Convenience overloading ofget(Object)intgetInt(int index) Convenience overloading ofget(Object)getNode(int index) Convenience overloading ofget(int)getString(int index) Convenience overloading ofget(Object)booleanisArray()Easy alternative to 'instanceof' to differentiate JSNode from JSArray (which subclasses JSNode).booleanisEmpty()iterator()keySet()intlength()Overloading ofput(String, Object)for completion, really just callsset(int, Object)Override of JSNode.put(String, Object) to parseindexas an Integer and store the result inobjectsinstead of JSNode.propertiesremove(int index) Removes columnindexif it exists.Override of JSNode.remove(Object) to parseindexas an Integer and remove the column fromobjectsinstead of removing the key from JSNode.propertiesSetsobjects[index]to value expanding the size ofobjectsas much as is required.intsize()values()Methods inherited from class io.inversion.utils.JSNode
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, withMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
objects
The objects stored in this JSArray.This replaces the use of the JSNode.properties map from the superclass.
-
-
Constructor Details
-
JSArray
-
-
Method Details
-
isArray
public boolean isArray()Description copied from class:JSNodeEasy alternative to 'instanceof' to differentiate JSNode from JSArray (which subclasses JSNode). -
put
Override of JSNode.put(String, Object) to parseindexas an Integer and store the result inobjectsinstead of JSNode.propertiesPut/set/add are basically synonyms.
-
put
Overloading ofput(String, Object)for completion, really just callsset(int, Object)Put/set/add are basically synonyms.
- Parameters:
index- the zero based property index to storevalue- a JSNode, JSArray, or compatible Java type- Returns:
- the prior value at
index - See Also:
-
set
Setsobjects[index]to value expanding the size ofobjectsas much as is required.Put/set/add are basically synonyms.
- Parameters:
index- the zero based property index to storevalue- a JSNode, JSArray, or compatible Java type- Returns:
- the prior value at
indexif it exists - Throws:
ArrayIndexOutOfBoundsException- only if index is @lt; 0
-
add
Overloading ofset(int, Object)- Parameters:
index- the zero based property index to storevalue- a JSNode, JSArray, or compatible Java type
-
add
Addsobjectto the end ofobjects- Parameters:
value- a JSNode, JSArray, or compatible Java type
-
addAll
Adds all elements fromarrayto the end ofobjects- Parameters:
array- an array of elements to add
-
remove
Override of JSNode.remove(Object) to parseindexas an Integer and remove the column fromobjectsinstead of removing the key from JSNode.properties -
remove
Removes columnindexif it exists.Will not throw ArrayIndexOutOfBoundsException
- Parameters:
index- the element/column to remove fromobjects- Returns:
- the prior value at
indexif it exits
-
get
Override of JSNode.get(Object) to parseindexas an Integer and pull fromobjectsinstead of JSNode.properties -
get
Gets the object atindexand will not throw ArrayIndexOutOfBoundsException- Parameters:
index- the zero based property index to get- Returns:
- the object at
indexif it exists else, null
-
getNode
Convenience overloading ofget(int)- Parameters:
index- the zero based property index to get- Returns:
- the value at
indexcast to a JSNode if exists else null - Throws:
ClassCastException- if the object found is not a JSNode- See Also:
-
getArray
Convenience overloading ofget(Object)- Parameters:
index- the zero based property index to get- Returns:
- the value at
indexcast to a JSArray if exists else null - Throws:
ClassCastException- if the object found is not a JSArray- See Also:
-
getString
Convenience overloading ofget(Object)- Parameters:
index- the zero based property index to get- Returns:
- the value of property
namestringified if it exists else null - See Also:
-
getInt
public int getInt(int index) Convenience overloading ofget(Object)- Parameters:
index- the zero based property index to get- Returns:
- the value at
indexstringified and parsed as an int if it exists else -1 - See Also:
-
getDouble
public double getDouble(int index) Convenience overloading ofget(Object)- Parameters:
index- the zero based property index to get- Returns:
- the value at
indexstringified and parsed as a double if it exists else -1 - See Also:
-
getBoolean
public boolean getBoolean(int index) Convenience overloading ofget(int)- Parameters:
index- the zero based property index to get- Returns:
- the value at
indexstringified and parsed as a boolean if it exists else false - See Also:
-
keySet
-
asList
Description copied from class:JSNodeReturns this object as the only element in a list.JSArray 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; } -
asArray
Description copied from class:JSNodeSimilar to #asList() but instead of returning a List, it returns a this JSNode as the only item in a JSArray.JSArray overrides this method to simply return 'this'.
-
asMap
-
contains
-
isEmpty
public boolean isEmpty() -
clear
public void clear()Description copied from class:JSNodeRemoves all properties -
size
public int size() -
length
public int length() -
iterator
-
values
-