Package net.dv8tion.jda.api.utils.data
Class DataArray
java.lang.Object
net.dv8tion.jda.api.utils.data.DataArray
- All Implemented Interfaces:
Iterable<Object>,SerializableArray
Represents a list of values used in communication with the Discord API.
Throws IndexOutOfBoundsException
if provided with index out of bounds.
This class is not Thread-Safe
-
Method Summary
Modifier and TypeMethodDescriptionAppends the provided value to the end of the array.addAll(Collection<?> values) Appends the provided values to the end of the array.Appends the provided values to the end of the array.static DataArrayempty()Creates a new empty DataArray, ready to be populated with values.booleanstatic DataArrayfromCollection(Collection<?> col) Creates a new DataArray and populates it with the contents of the provided collection.static DataArrayfromETF(byte[] data) Parses usingExTermDecoder.static DataArrayfromJson(InputStream json) Parses a JSON Array into a DataArray instance.static DataArrayParses a JSON Array into a DataArray instance.static DataArrayParses a JSON Array into a DataArray instance.getArray(int index) Resolves the value at the specified index to a DataArraybooleangetBoolean(int index) Resolves the value at the specified index to a boolean.booleangetBoolean(int index, boolean defaultValue) Resolves the value at the specified index to a boolean.doublegetDouble(int index) Resolves the value at the specified index to a double.doublegetDouble(int index, double defaultValue) Resolves the value at the specified index to a double.intgetInt(int index) Resolves the value at the specified index to an int.intgetInt(int index, int defaultValue) Resolves the value at the specified index to an int.longgetLong(int index) Resolves the value at the specified index to a long.longgetLong(int index, long defaultValue) Resolves the value at the specified index to a long.getObject(int index) Resolves the value at the specified index to a DataObjectgetOffsetDateTime(int index) Resolves the value at the specified index to anOffsetDateTime.getOffsetDateTime(int index, OffsetDateTime defaultValue) Resolves the value at the specified index to anOffsetDateTime.getString(int index) Resolves the value at the specified index to a String.Resolves the value at the specified index to a String.intgetUnsignedInt(int index) Resolves the value at the specified index to an unsigned int.intgetUnsignedInt(int index, int defaultValue) Resolves the value at the specified index to an unsigned int.longgetUnsignedLong(int index) Resolves the value at the specified index to an unsigned long.longgetUnsignedLong(int index, long defaultValue) Resolves the value at the specified index to an unsigned long.inthashCode()Inserts the specified value at the provided index.booleanisEmpty()Whether this array is emptybooleanisNull(int index) Whether the value at the specified index is null.booleanWhether the value at the specified index is of the specified type.iterator()intlength()The length of the array.remove(int index) Removes the value at the specified index.Removes the specified value.<T> Stream<T>stream(BiFunction<? super DataArray, Integer, ? extends T> mapper) SerializedDataArrayfor this object.byte[]toETF()Serializes this object as ETF LIST term.byte[]toJson()Serializes this object as JSON.toList()Converts this DataArray to aList.toString()Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
empty
Creates a new empty DataArray, ready to be populated with values.- Returns:
- An empty DataArray instance
- See Also:
-
fromCollection
Creates a new DataArray and populates it with the contents of the provided collection.- Parameters:
col- TheCollection- Returns:
- A new DataArray populated with the contents of the collection
-
fromJson
Parses a JSON Array into a DataArray instance.- Parameters:
json- The correctly formatted JSON Array- Returns:
- A new DataArray instance for the provided array
- Throws:
ParsingException- If the provided JSON is incorrectly formatted
-
fromJson
Parses a JSON Array into a DataArray instance.- Parameters:
json- The correctly formatted JSON Array- Returns:
- A new DataArray instance for the provided array
- Throws:
ParsingException- If the provided JSON is incorrectly formatted or an I/O error occurred
-
fromJson
Parses a JSON Array into a DataArray instance.- Parameters:
json- The correctly formatted JSON Array- Returns:
- A new DataArray instance for the provided array
- Throws:
ParsingException- If the provided JSON is incorrectly formatted or an I/O error occurred
-
fromETF
Parses usingExTermDecoder. The provided data must start with the correct version header (131).- Parameters:
data- The data to decode- Returns:
- A DataArray instance for the provided payload
- Throws:
IllegalArgumentException- If the provided data is nullParsingException- If the provided ETF payload is incorrectly formatted or an I/O error occurred- Since:
- 4.2.1
-
isNull
public boolean isNull(int index) Whether the value at the specified index is null.- Parameters:
index- The index to check- Returns:
- True, if the value at the index is null
-
isType
Whether the value at the specified index is of the specified type.- Parameters:
index- The index to checktype- The type to check- Returns:
- True, if the type check is successful
- See Also:
-
length
public int length()The length of the array.- Returns:
- The length of the array
-
isEmpty
public boolean isEmpty()Whether this array is empty- Returns:
- True, if this array is empty
-
getObject
Resolves the value at the specified index to a DataObject- Parameters:
index- The index to resolve- Returns:
- The resolved DataObject
- Throws:
ParsingException- If the value is of the wrong type or missing
-
getArray
Resolves the value at the specified index to a DataArray- Parameters:
index- The index to resolve- Returns:
- The resolved DataArray
- Throws:
ParsingException- If the value is of the wrong type or null
-
getString
Resolves the value at the specified index to a String.- Parameters:
index- The index to resolve- Returns:
- The resolved String
- Throws:
ParsingException- If the value is of the wrong type or null
-
getString
Resolves the value at the specified index to a String.- Parameters:
index- The index to resolvedefaultValue- Alternative value to use when the value associated with the index is null- Returns:
- The resolved String
- Throws:
ParsingException- If the value is of the wrong type
-
getBoolean
public boolean getBoolean(int index) Resolves the value at the specified index to a boolean.- Parameters:
index- The index to resolve- Returns:
- True, if the value is present and set to true. Otherwise false.
- Throws:
ParsingException- If the value is of the wrong type
-
getBoolean
public boolean getBoolean(int index, boolean defaultValue) Resolves the value at the specified index to a boolean.- Parameters:
index- The index to resolvedefaultValue- Alternative value to use when the value associated with the index is null- Returns:
- True, if the value is present and set to true. False, if it is set to false. Otherwise defaultValue.
- Throws:
ParsingException- If the value is of the wrong type
-
getInt
public int getInt(int index) Resolves the value at the specified index to an int.- Parameters:
index- The index to resolve- Returns:
- The resolved int value
- Throws:
ParsingException- If the value is of the wrong type
-
getInt
public int getInt(int index, int defaultValue) Resolves the value at the specified index to an int.- Parameters:
index- The index to resolvedefaultValue- Alternative value to use when the value associated with the index is null- Returns:
- The resolved int value
- Throws:
ParsingException- If the value is of the wrong type
-
getUnsignedInt
public int getUnsignedInt(int index) Resolves the value at the specified index to an unsigned int.- Parameters:
index- The index to resolve- Returns:
- The resolved unsigned int value
- Throws:
ParsingException- If the value is of the wrong type
-
getUnsignedInt
public int getUnsignedInt(int index, int defaultValue) Resolves the value at the specified index to an unsigned int.- Parameters:
index- The index to resolvedefaultValue- Alternative value to use when the value associated with the index is null- Returns:
- The resolved unsigned int value
- Throws:
ParsingException- If the value is of the wrong type
-
getLong
public long getLong(int index) Resolves the value at the specified index to a long.- Parameters:
index- The index to resolve- Returns:
- The resolved long value
- Throws:
ParsingException- If the value is of the wrong type
-
getLong
public long getLong(int index, long defaultValue) Resolves the value at the specified index to a long.- Parameters:
index- The index to resolvedefaultValue- Alternative value to use when the value associated with the index is null- Returns:
- The resolved long value
- Throws:
ParsingException- If the value is of the wrong type
-
getUnsignedLong
public long getUnsignedLong(int index) Resolves the value at the specified index to an unsigned long.- Parameters:
index- The index to resolve- Returns:
- The resolved unsigned long value
- Throws:
ParsingException- If the value is of the wrong type
-
getOffsetDateTime
Resolves the value at the specified index to anOffsetDateTime.
Note: This method should be used on ISO8601 timestamps- Parameters:
index- The index to resolve- Returns:
- Possibly-null
OffsetDateTimeobject representing the timestamp - Throws:
ParsingException- If the value is missing, null, or not a valid ISO8601 timestamp
-
getOffsetDateTime
@Contract("_, !null -> !null") public OffsetDateTime getOffsetDateTime(int index, @Nullable OffsetDateTime defaultValue) Resolves the value at the specified index to anOffsetDateTime.
Note: This method should only be used on ISO8601 timestamps- Parameters:
index- The index to resolvedefaultValue- Alternative value to use when no value or null value is associated with the key- Returns:
- Possibly-null
OffsetDateTimeobject representing the timestamp - Throws:
ParsingException- If the value is not a valid ISO8601 timestamp
-
getUnsignedLong
public long getUnsignedLong(int index, long defaultValue) Resolves the value at the specified index to an unsigned long.- Parameters:
index- The index to resolvedefaultValue- Alternative value to use when the value associated with the index is null- Returns:
- The resolved unsigned long value
- Throws:
ParsingException- If the value is of the wrong type
-
getDouble
public double getDouble(int index) Resolves the value at the specified index to a double.- Parameters:
index- The index to resolve- Returns:
- The resolved double value
- Throws:
ParsingException- If the value is of the wrong type
-
getDouble
public double getDouble(int index, double defaultValue) Resolves the value at the specified index to a double.- Parameters:
index- The index to resolvedefaultValue- Alternative value to use when the value associated with the index is null- Returns:
- The resolved double value
- Throws:
ParsingException- If the value is of the wrong type
-
add
Appends the provided value to the end of the array.- Parameters:
value- The value to append- Returns:
- A DataArray with the value inserted at the end
-
addAll
Appends the provided values to the end of the array.- Parameters:
values- The values to append- Returns:
- A DataArray with the values inserted at the end
-
addAll
Appends the provided values to the end of the array.- Parameters:
array- The values to append- Returns:
- A DataArray with the values inserted at the end
-
insert
Inserts the specified value at the provided index.- Parameters:
index- The target indexvalue- The value to insert- Returns:
- A DataArray with the value inserted at the specified index
-
remove
Removes the value at the specified index.- Parameters:
index- The target index to remove- Returns:
- A DataArray with the value removed
-
remove
Removes the specified value.- Parameters:
value- The value to remove- Returns:
- A DataArray with the value removed
-
toJson
Serializes this object as JSON.- Returns:
- byte array containing the JSON representation of this object
-
toETF
Serializes this object as ETF LIST term.- Returns:
- byte array containing the encoded ETF term
- Since:
- 4.2.1
-
toString
-
toPrettyString
-
toList
Converts this DataArray to aList.- Returns:
- The resulting list
-
iterator
-
stream
-
toDataArray
Description copied from interface:SerializableArraySerializedDataArrayfor this object.- Specified by:
toDataArrayin interfaceSerializableArray- Returns:
DataArray
-
equals
-
hashCode
public int hashCode()
-