public class JsonArray extends JsonElement
A strongly-typed list of item type JsonElement
?, inheriting from JsonElement
rather than the usual ListBase
.
Uses the property and function naming conventions of the
JavaScript Array object.
Modifier and Type | Field and Description |
---|---|
static JsonArray |
empty |
TYPE_ARRAY, TYPE_BOOLEAN, TYPE_NUMBER, TYPE_OBJECT, TYPE_STRING
Constructor and Description |
---|
JsonArray()
See JsonArray(int).
|
JsonArray(int capacity)
Construct a new list with
JsonArray.length of zero and specified initial capacity . |
Modifier and Type | Method and Description |
---|---|
void |
add(JsonElement item)
Add
item to the end of this list. |
void |
addAll(JsonArray list)
Add all the items of
list to the end of this list. |
JsonArray |
addThis(JsonElement item)
Add
item to the end of this list. |
void |
clear()
Remove all items from this list.
|
JsonArray |
copy()
Return a shallow copy of this list.
|
JsonElement |
first()
Return (nullable) The first item in this list.
|
static JsonArray |
fromElement(JsonElement value)
Return the 'value' cast as a
JsonArray . |
JsonElement |
get(int index)
Return (nullable) The item in this list at the specified
index . |
JsonArray |
getArray(int index)
Return an item of this array cast as a
JsonArray . |
JsonObject |
getObject(int index)
Return an item of this array cast as a
JsonObject . |
java.lang.String |
getString(int index)
Return an item of this array cast as a
string . |
int |
getType()
Return type of JSON element.
|
com.sap.cloud.server.odata.core.UntypedList |
getUntypedList()
Return the underlying untyped list of objects.
|
boolean |
includes(JsonElement item)
Return
true if this list contains item . |
int |
indexOf(JsonElement item)
|
int |
indexOf(JsonElement item,
int start)
Return first index in this list of
item , or -1 if not found. |
void |
insertAll(int index,
JsonArray list)
Insert all items of
list into this list, before the item (if any) at index . |
void |
insertAt(int index,
JsonElement item)
Insert
item into this list, before the item (if any) at index . |
boolean |
isEmpty()
Return
true if this list contains no items. |
JsonElement |
last()
Return (nullable) The last item in this list.
|
int |
lastIndexOf(java.lang.Object item)
|
int |
lastIndexOf(java.lang.Object item,
int start)
Return last index in this list of
item , or -1 if not found. |
int |
length()
Return the number of items in this list.
|
void |
removeAt(int index)
Remove an item from the specified index in this list.
|
void |
removeRange(int start,
int end)
Remove a range of items from this list.
|
void |
reverse()
Reverse the order of the items in this list.
|
void |
set(int index,
JsonElement item)
Set the item in this list at the specified
index . |
JsonElement |
single()
Return (nullable) A single item from this list.
|
JsonArray |
slice(int start)
See slice(int, int).
|
JsonArray |
slice(int start,
int end)
Return a slice of this list from index
start (inclusive) to index end (exclusive). |
void |
sort()
Sort the items in this list.
|
java.lang.String |
toString()
Return the array in JSON format.
|
applyVersion, format, parse, parseArray, parseObject, parseOptimized
public static final JsonArray empty
public JsonArray()
public JsonArray(int capacity)
Construct a new list with JsonArray.length
of zero and specified initial capacity
.
A list can expand in length beyond its initial capacity, but best performance
will be obtained if the initial capacity is close to the list's maximum length.
capacity
- Initial capacity.public void add(JsonElement item)
Add item
to the end of this list.
item
- (nullable) Item to be added.public void addAll(JsonArray list)
Add all the items of list
to the end of this list.
list
- Items to be added.public JsonArray addThis(JsonElement item)
Add item
to the end of this list.
item
- (nullable) Item to be added.public void clear()
Remove all items from this list.
public JsonArray copy()
Return a shallow copy of this list.
public JsonElement first()
Return (nullable) The first item in this list.
EmptyListException
if the list is empty.
public static JsonArray fromElement(JsonElement value)
Return the 'value' cast as a JsonArray
.
JsonException
if value
is not an instanceof of JsonArray
.
value
- (nullable) Element value.JsonArray
.public JsonElement get(int index)
Return (nullable) The item in this list at the specified index
.
ListIndexException
if index
is out of range (0 to JsonArray.length
- 1).
index
- Zero-based index.public JsonArray getArray(int index)
Return an item of this array cast as a JsonArray
.
index
- Item index.JsonArray
.public JsonObject getObject(int index)
Return an item of this array cast as a JsonObject
.
index
- Item index.JsonObject
.public java.lang.String getString(int index)
Return an item of this array cast as a string
.
index
- Item index.string
.public int getType()
Return type of JSON element.
constants.
getType
in class JsonElement
public com.sap.cloud.server.odata.core.UntypedList getUntypedList()
Return the underlying untyped list of objects. Use with care, avoiding the addition of objects with an incorrect item type.
public boolean includes(JsonElement item)
Return true
if this list contains item
.
item
- (nullable) Item for comparison.true
if this list contains item
.public int indexOf(JsonElement item)
item
- Item parameter.public int indexOf(JsonElement item, int start)
Return first index in this list of item
, or -1
if not found.
item
- (nullable) Item for comparison.start
- Zero-based starting index (search moves forwards from this index).item
, or -1
if not found.public void insertAll(int index, JsonArray list)
Insert all items of list
into this list, before the item (if any) at index
.
ListIndexException
if index
is out of range (0 to JsonArray.length
).
index
- Zero-based index.list
- List of items to be inserted.public void insertAt(int index, JsonElement item)
Insert item
into this list, before the item (if any) at index
.
ListIndexException
if index
is out of range (0 to JsonArray.length
).
index
- Zero-based index.item
- (nullable) Item to be added.public boolean isEmpty()
Return true
if this list contains no items.
true
if this list contains no items.public JsonElement last()
Return (nullable) The last item in this list.
EmptyListException
if the list is empty.
public int lastIndexOf(java.lang.Object item)
item
- Item parameter.public int lastIndexOf(java.lang.Object item, int start)
Return last index in this list of item
, or -1 if not found.
item
- (nullable) Item for comparison.start
- Zero-based starting index (search moves backwards from this index).item
, or -1 if not found.public int length()
Return the number of items in this list.
public void removeAt(int index)
Remove an item from the specified index in this list.
index
- Index of the item to be removed.public void removeRange(int start, int end)
Remove a range of items from this list.
start
- Starting index (inclusive) for items to be removed.end
- Ending index (exclusive) for items to be removed.public void reverse()
Reverse the order of the items in this list.
public void set(int index, JsonElement item)
Set the item in this list at the specified index
.
index
- Zero-based index.item
- (nullable) Item value.public JsonElement single()
Return (nullable) A single item from this list.
EmptyListException
if the list has no items, NotUniqueException
if the list has multiple items.
public JsonArray slice(int start)
start
- Start parameter.public JsonArray slice(int start, int end)
Return a slice of this list from index start
(inclusive) to index end
(exclusive).
start
- Zero-based starting index (inclusive), or negative for starting index relative to the end of this list.end
- Zero-based ending index (exclusive), or negative for ending index relative to the end of this list.start
(inclusive) to index end
(exclusive).public void sort()
Sort the items in this list.
public java.lang.String toString()
Return the array in JSON format.
toString
in class JsonElement