Package net.dv8tion.jda.api.utils.data
Class DataArray
- java.lang.Object
-
- net.dv8tion.jda.api.utils.data.DataArray
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DataArrayadd(Object value)Appends the provided value to the end of the array.DataArrayaddAll(Collection<?> values)Appends the provided values to the end of the array.DataArrayaddAll(DataArray array)Appends the provided values to the end of the array.static DataArrayempty()Creates a new empty DataArray, ready to be populated with values.static DataArrayfromCollection(Collection<?> col)Creates a new DataArray and populates it with the contents of the provided collection.static DataArrayfromJson(InputStream json)Parses a JSON Array into a DataArray instance.static DataArrayfromJson(Reader json)Parses a JSON Array into a DataArray instance.static DataArrayfromJson(String json)Parses a JSON Array into a DataArray instance.DataArraygetArray(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.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.DataObjectgetObject(int index)Resolves the value at the specified index to a DataObjectStringgetString(int index)Resolves the value at the specified index to a String.StringgetString(int index, String defaultValue)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.DataArrayinsert(int index, Object value)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.booleanisType(int index, DataType type)Whether the value at the specified index is of the specified type.Iterator<Object>iterator()intlength()The length of the array.DataArrayremove(int index)Removes the value at the specified index.DataArrayremove(Object value)Removes the specified value.List<Object>toList()Converts this DataArray to aList.StringtoString()-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
empty
@Nonnull public static DataArray empty()
Creates a new empty DataArray, ready to be populated with values.- Returns:
- An empty DataArray instance
- See Also:
add(Object)
-
fromCollection
@Nonnull public static DataArray fromCollection(@Nonnull Collection<?> col)
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
@Nonnull public static DataArray fromJson(@Nonnull String json)
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
@Nonnull public static DataArray fromJson(@Nonnull InputStream json)
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
@Nonnull public static DataArray fromJson(@Nonnull Reader json)
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
-
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
public boolean isType(int index, @Nonnull DataType type)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:
DataType.isType(Object)
-
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
@Nonnull public DataObject getObject(int index)
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
@Nonnull public DataArray getArray(int index)
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
@Nonnull public String getString(int index)
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
@Contract("_, !null -> !null") public String getString(int index, @Nullable String defaultValue)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
-
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
-
add
@Nonnull public DataArray add(@Nullable Object value)
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
@Nonnull public DataArray addAll(@Nonnull Collection<?> values)
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
@Nonnull public DataArray addAll(@Nonnull DataArray array)
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
@Nonnull public DataArray insert(int index, @Nullable Object value)
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
@Nonnull public DataArray remove(int index)
Removes the value at the specified index.- Parameters:
index- The target index to remove- Returns:
- A DataArray with the value removed
-
remove
@Nonnull public DataArray remove(@Nullable Object value)
Removes the specified value.- Parameters:
value- The value to remove- Returns:
- A DataArray with the value removed
-
toList
@Nonnull public List<Object> toList()
Converts this DataArray to aList.- Returns:
- The resulting list
-
-