public final class SimpleJSONArray extends ArrayList<Object> implements JSONArray
JSONArray
, which is a
common, non-thread-safe data format for a collection of Object
s.
The contents of the JSONArray
are only validated as JSON values upon
serialization (see JSONSerializable.serialize()
). This means that all
values added to a JSONArray
must be recognized by the
JSONParser
for it to be considered a true JSONArray
. Until
such a recognition has been reached, the item should be considered a
JSONSerializable
ArrayList
.
modCount
Constructor and Description |
---|
SimpleJSONArray()
Constructs a new
JSONArray . |
SimpleJSONArray(@NotNull Collection<?> data)
Constructs a new
JSONArray with the specified Collection
of data loaded into the underlying ArrayList to start. |
SimpleJSONArray(int initialCapacity)
Constructs a new
JSONArray with the specified initial capacity. |
Modifier and Type | Method and Description |
---|---|
void |
addEntry(@Nullable Object value)
Adds the given value at the end of this
JSONArray . |
@Nullable JSONArray |
getArray(int index)
Gets the
JSONArray value at the given index. |
@Nullable JSONArray |
getArray(int index,
@Nullable JSONArray def)
Gets the
JSONArray value at the given index. |
boolean |
getBoolean(int index)
Gets the boolean value at the given index.
|
boolean |
getBoolean(int index,
boolean def)
Gets the boolean value at the given index.
|
byte |
getByte(int index)
Gets the byte value at the given index.
|
byte |
getByte(int index,
byte def)
Gets the byte value at the given index.
|
double |
getDouble(int index)
Gets the double value at the given index.
|
double |
getDouble(int index,
double def)
Gets the double value at the given index.
|
float |
getFloat(int index)
Gets the float value at the given index.
|
float |
getFloat(int index,
float def)
Gets the float value at the given index.
|
int |
getInteger(int index)
Gets the integer value at the given index.
|
int |
getInteger(int index,
int def)
Gets the integer value at the given index.
|
long |
getLong(int index)
Gets the long value at the given index.
|
long |
getLong(int index,
long def)
Gets the long value at the given index.
|
@Nullable JSONObject |
getObject(int index)
Gets the
JSONObject value at the given index. |
@Nullable JSONObject |
getObject(int index,
@Nullable JSONObject def)
Gets the
JSONObject value at the given index. |
short |
getShort(int index)
Gets the short value at the given index.
|
short |
getShort(int index,
short def)
Gets the short value at the given index.
|
@Nullable String |
getString(int index)
Gets the
String value at the given index. |
@Nullable String |
getString(int index,
@Nullable String def)
Gets the
String value at the given index. |
void |
insertEntry(int index,
@Nullable Object value)
Inserts the given value at the given index, adding 1 to the index of
every entry after the given index.
|
boolean |
isArray(int index)
Checks if there is a
JSONArray value at the given index. |
boolean |
isBoolean(int index)
Checks if there is a boolean value at the given index.
|
boolean |
isByte(int index)
Checks if there is a byte value at the given index.
|
boolean |
isDouble(int index)
Checks if there is a double value at the given index.
|
boolean |
isFloat(int index)
Checks if there is a float value at the given index.
|
boolean |
isInteger(int index)
Checks if there is an integer value at the given index.
|
boolean |
isLong(int index)
Checks if there is a long value at the given index.
|
boolean |
isNull(int index)
Checks if there is a null value at the given index.
|
boolean |
isObject(int index)
Checks if there is a
JSONObject value at the given index. |
boolean |
isShort(int index)
Checks if there is a short value at the given index.
|
boolean |
isString(int index)
Checks if there is a
String value at the given index. |
@NotNull Iterator<Object> |
iterator()
|
@NotNull String |
serialize()
Serializes this
JSONSerializable into a string. |
void |
setEntry(int index,
@Nullable Object value)
Sets the given index to the given value, overwriting any other value that
was previously set there.
|
int |
size()
Gets the size of this
JSONArray . |
void |
unsetEntry(int index)
Removes the entry at the given index, subtracting 1 from the index of
every entry after the given index.
|
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, sort, spliterator, subList, toArray, toArray, trimToSize
equals, hashCode
containsAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
containsAll, equals, hashCode
parallelStream, stream
public SimpleJSONArray()
JSONArray
.ArrayList()
public SimpleJSONArray(int initialCapacity)
JSONArray
with the specified initial capacity.initialCapacity
- The initial capacity that the underlying
ArrayList
should allocate for.ArrayList(int)
public SimpleJSONArray(@NotNull @NotNull Collection<?> data)
JSONArray
with the specified Collection
of data loaded into the underlying ArrayList
to start.data
- The Collection
whose data will be placed into the
JSONArray
to start.ArrayList(Collection)
public int size()
JSONArray
.@NotNull public @NotNull Iterator<Object> iterator()
iterator
in interface Iterable<Object>
iterator
in interface Collection<Object>
iterator
in interface List<Object>
iterator
in interface JSONArray
iterator
in class ArrayList<Object>
Iterator
over the entries in this JSONArray
.public void addEntry(@Nullable @Nullable Object value)
JSONArray
.public void insertEntry(int index, @Nullable @Nullable Object value) throws IndexOutOfBoundsException
If the given index is less than 0 or greater than the current size of
this JSONArray
minus 1, an IndexOutOfBoundsException
will
be thrown.
insertEntry
in interface JSONArray
index
- The index to insert into.value
- The value to insert.IndexOutOfBoundsException
public void setEntry(int index, @Nullable @Nullable Object value) throws IndexOutOfBoundsException
If the given index is less than 0 or greater than the current size of
this JSONArray
minus 1, an IndexOutOfBoundsException
will
be thrown.
setEntry
in interface JSONArray
index
- The index to set at.value
- The value to set.IndexOutOfBoundsException
public void unsetEntry(int index) throws IndexOutOfBoundsException
If the given index is less than 0 or greater than the current size of
this JSONArray
minus 1, an IndexOutOfBoundsException
will
be thrown.
unsetEntry
in interface JSONArray
index
- The index of the entry to remove.IndexOutOfBoundsException
public boolean isNull(int index)
This will return false
if the index is outside this
JSONArray
's bounds, or if there is an entry at the index and the
value is not null
.
This will return true
if the d at the index is null
(the index must be within this JSONArray
's bounds), regardless of
what type of Object
the entry is supposed to be.
public boolean isBoolean(int index)
This will return false
if the index is out of this
JSONArray
's bounds, or if there is no entry (null
), or if
the entry is not a boolean.
public boolean getBoolean(int index)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a boolean, false
will be returned.
getBoolean
in interface JSONArray
index
- The index of the boolean to retrieve.JSONArray.getBoolean(int, boolean)
public boolean getBoolean(int index, boolean def)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a boolean, the default
value will be returned.
getBoolean
in interface JSONArray
index
- The index of the boolean to retrieve.def
- The default value.public boolean isByte(int index)
This will return false
if the index is out of this
JSONArray
's bounds, or if there is no entry (null
), or if
the entry is not a byte.
public byte getByte(int index)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a byte, (byte) 0
will be returned.
getByte
in interface JSONArray
index
- The index of the byte to retrieve.JSONArray.getByte(int, byte)
public byte getByte(int index, byte def)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a byte, the default
value will be returned.
public boolean isShort(int index)
This will return false
if the index is out of this
JSONArray
's bounds, or if there is no entry (null
), or if
the entry is not a short.
public short getShort(int index)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a short,
(short) 0
will be returned.
getShort
in interface JSONArray
index
- The index of the short to retrieve.JSONArray.getShort(int, short)
public short getShort(int index, short def)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a short, the default
value will be returned.
public boolean isInteger(int index)
This will return false
if the index is out of this
JSONArray
's bounds, or if there is no entry (null
), or if
the entry is not an integer.
public int getInteger(int index)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not an integer,
0
will be returned.
getInteger
in interface JSONArray
index
- The index of the integer to retrieve.JSONArray.getInteger(int, int)
public int getInteger(int index, int def)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not an integer, the default
value will be returned.
getInteger
in interface JSONArray
index
- The index of the integer to retrieve.def
- The default value.public boolean isLong(int index)
This will return false
if the index is out of this
JSONArray
's bounds, or if there is no entry (null
), or if
the entry is not a long.
public long getLong(int index)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a long, 0L
will be returned.
getLong
in interface JSONArray
index
- The index of the long to retrieve.JSONArray.getLong(int, long)
public long getLong(int index, long def)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a long, the default
value will be returned.
public boolean isFloat(int index)
This will return false
if the index is out of this
JSONArray
's bounds, or if there is no entry (null
), or if
the entry is not a float.
public float getFloat(int index)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a float, 0.0F
will be returned.
getFloat
in interface JSONArray
index
- The index of the float to retrieve.JSONArray.getFloat(int, float)
public float getFloat(int index, float def)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a float, the default
value will be returned.
public boolean isDouble(int index)
This will return false
if the index is out of this
JSONArray
's bounds, or if there is no entry (null
), or if
the entry is not a double.
public double getDouble(int index)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a double, 0.0D
will be returned.
getDouble
in interface JSONArray
index
- The index of the double to retrieve.JSONArray.getDouble(int, double)
public double getDouble(int index, double def)
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a double, the default
value will be returned.
public boolean isString(int index)
@Nullable public @Nullable String getString(int index)
String
value at the given index.
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a String
,
null
will be returned.
getString
in interface JSONArray
index
- The index of the String
to retrieve.String
value at the index.JSONArray.getString(int, String)
@Contract(value="_, !null -> !null") @Nullable public @Nullable String getString(int index, @Nullable @Nullable String def)
public boolean isArray(int index)
@Nullable public @Nullable JSONArray getArray(int index)
JSONArray
value at the given index.
If the index is out of the JSONArray
's bounds, no entry set
(null
), or the value at the index is not a JSONArray
,
null
will be returned.
getArray
in interface JSONArray
index
- The index of the JSONArray
to retrieve.JSONArray
value at the index.JSONArray.getArray(int, JSONArray)
@Contract(value="_, !null -> !null") @Nullable public @Nullable JSONArray getArray(int index, @Nullable @Nullable JSONArray def)
public boolean isObject(int index)
JSONObject
value at the given index.
This will return false
if the index is out of this
JSONObject
's bounds, or if there is no entry (null
), or
if the entry is not a JSONObject
.
isObject
in interface JSONArray
index
- The index to check.true
if there is a JSONObject
at the given index,
false
otherwise.@Nullable public @Nullable JSONObject getObject(int index)
JSONObject
value at the given index.
If the index is out of the JSONObject
's bounds, no entry set
(null
), or the value at the index is not a JSONObject
,
null
will be returned.
getObject
in interface JSONArray
index
- The index of the JSONObject
to retrieve.JSONObject
value at the index.JSONArray.getObject(int, JSONObject)
@Contract(value="_, !null -> !null") @Nullable public @Nullable JSONObject getObject(int index, @Nullable @Nullable JSONObject def)
JSONObject
value at the given index.
If the index is out of the JSONObject
's bounds, no entry set
(null
), or the value at the index is not a JSONObject
,
the default value will be returned.
getObject
in interface JSONArray
index
- The index of the JSONObject
to retrieve.def
- The default value.JSONObject
value at the index.@NotNull public @NotNull String serialize() throws JSONException
JSONSerializable
into a string.serialize
in interface JSONSerializable
String
.JSONException
- If an error occurs while serializing the data.Copyright © 2021 BSPF Systems, LLC. All rights reserved.