Package org.ghotibeaun.json
Interface JSONArray
- All Superinterfaces:
Comparable<JSONNode>
,Iterable<JSONValue<?>>
,JSONListNode
,JSONNode
,Serializable
public interface JSONArray extends JSONListNode
Interface holding an array of JSONValue objects
- Author:
- jearley
-
Method Summary
Modifier and Type Method Description void
add(Boolean bool)
Add a boolean valuevoid
add(Number number)
Add a number valuevoid
add(String string)
Add a String value to the JSONArrayvoid
add(JSONArray array)
Add a JSONArray valuedefault void
add(JSONNode node)
Add a JSONNode instance.void
add(JSONObject obj)
Add a JSONObject valueboolean
getBoolean(int index)
Return a boolean valuedefault <T> T
getFirstValue()
Return the first value in the arrayint
getInt(int index)
Return a integer valueJSONArray
getJSONArray(int index)
Return a JSONArray valueJSONObject
getJSONObject(int index)
Return a JSONOBject valuedefault <T> T
getLastValue()
Return the last value in the arraylong
getLong(int index)
Return a long valueNumber
getNumber(int index)
Return a Number valueString
getString(int index)
Get a String valuedefault <T> T
getValue(int index)
Return the value at the specified indexJSONValueType
getValueType(int index)
Return the value type for value at the specified indexdefault void
merge(JSONArray secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)
Merge another JSONArray into this instance.default JSONArray
mergeToCopy(JSONArray secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)
Merge the current JSONArray instance with another and return the merged instance.Methods inherited from interface java.lang.Comparable
compareTo
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface org.ghotibeaun.json.JSONListNode
add, addAll, clear, get, getFirst, getLast, getList, getValues, insert, insert, isEmpty, isNull, iterator, remove, size, toList
Methods inherited from interface org.ghotibeaun.json.JSONNode
asJSONArray, asJSONObject, isArray, isEquivalent, isObject, prettyPrint, prettyPrint, select, select, select, selectValue, selectValue, selectValue, toJSONString, write, write, write, write, write, write, write, write
-
Method Details
-
add
Add a String value to the JSONArray- Parameters:
string
- the String value.
-
add
Add a boolean value- Parameters:
bool
- the boolean value
-
add
Add a number value- Parameters:
number
- the number value
-
add
Add a JSONArray value- Parameters:
array
- a JSONArrray
-
add
Add a JSONObject value- Parameters:
obj
- the JSONObject
-
add
Add a JSONNode instance. This will be converted to either a JSONArray or JSONObject on inspection- Parameters:
node
- the JSONNode
-
getString
Get a String value- Parameters:
index
- the JSONArray index position- Returns:
- the String value of the array at that index
- Throws:
JSONInvalidValueTypeException
- thrown if value cannot be returned as String
-
getNumber
Return a Number value- Parameters:
index
- the JSONArray index position- Returns:
- A number
- Throws:
JSONInvalidValueTypeException
- thrown if value cannot be returned as Number
-
getLong
Return a long value- Parameters:
index
- the JSONArray index position- Returns:
- a long value
- Throws:
JSONInvalidValueTypeException
- thrown if value cannot be returned as long
-
getInt
Return a integer value- Parameters:
index
- the JSONArray index position- Returns:
- a integer value
- Throws:
JSONInvalidValueTypeException
- thrown if value cannot be returned as integer
-
getBoolean
Return a boolean value- Parameters:
index
- the JSONArray index position- Returns:
- a boolean value
- Throws:
JSONInvalidValueTypeException
- thrown if value cannot be returned as long
-
getJSONArray
Return a JSONArray value- Parameters:
index
- the JSONArray index position- Returns:
- a JSONArray value
- Throws:
JSONInvalidValueTypeException
- thrown if value cannot be returned as JSONArray
-
getJSONObject
Return a JSONOBject value- Parameters:
index
- the JSONArray index position- Returns:
- a JSONObject value
- Throws:
JSONInvalidValueTypeException
- thrown if value cannot be returned as JSONObject
-
getValueType
Return the value type for value at the specified index- Parameters:
index
- the JSONArray index position- Returns:
- the value type enum value
-
getValue
default <T> T getValue(int index)Return the value at the specified index- Parameters:
index
- the JSONArray index position- Returns:
- the casted value
-
getLastValue
default <T> T getLastValue()Return the last value in the array- Type Parameters:
T
- The value type- Returns:
- the last value in the array, or null if the array is empty
-
getFirstValue
default <T> T getFirstValue()Return the first value in the array- Type Parameters:
T
- the value type- Returns:
- the first value in the array, or null if the array is empty
-
merge
default void merge(JSONArray secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)Merge another JSONArray into this instance.HERE THERE BE DRAGONS: Once the merge happens, the original Node value is replaced. Know your data
- Parameters:
secondary
- the other JSONArray instance to mergearrayConflict
- the Array Conflict Strategy to useobjectConflict
- the Object Conflict Strategy to use
-
mergeToCopy
default JSONArray mergeToCopy(JSONArray secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)Merge the current JSONArray instance with another and return the merged instance. The original instance is left in its original state.- Parameters:
secondary
- the other JSONArray instance to mergearrayConflict
- the Array Conflict Strategy to useobjectConflict
- the Object Conflict Strategy to use- Returns:
-