Interface TomlArray
- All Known Subinterfaces:
MutableTomlArray
An array that can be edited is a MutableTomlArray; the arrays of a parse result are.
-
Method Summary
Modifier and TypeMethodDescriptiondefault @Nullable TomlCommentcomment(int index, TomlComment.Placement placement) Get the comment attached to a value at a placement.default List<TomlComment> comments(int index) Get the comments attached to a value.elements()Get the elements written in this array, in document order.entry(int index) Get the entry at an index.default Objectget(int index) Get a value at a specified index.default TomlArraygetArray(int index) Get an array at a specified index.default booleangetBoolean(int index) Get a boolean at a specified index.default doublegetDouble(int index) Get a double at a specified index.default LocalDategetLocalDate(int index) Get a local date at a specified index.default LocalDateTimegetLocalDateTime(int index) Get a local date time at a specified index.default LocalTimegetLocalTime(int index) Get a local time at a specified index.default longgetLong(int index) Get a long at a specified index.default OffsetDateTimegetOffsetDateTime(int index) Get an offset date time at a specified index.default StringgetString(int index) Get a string at a specified index.default TomlTablegetTable(int index) Get a table at a specified index.default @Nullable TomlPositioninputPositionOf(int index) Get the position where a value is defined in the TOML document.default booleanisArray(int index) trueif the value at an index is an array.default booleanisBoolean(int index) trueif the value at an index is a boolean.default booleanisDouble(int index) trueif the value at an index is a double.booleanisEmpty()trueif the array is empty.default booleanisLocalDate(int index) trueif the value at an index is a local date.default booleanisLocalDateTime(int index) trueif the value at an index is a local date-time.default booleanisLocalTime(int index) trueif the value at an index is a local time.default booleanisLong(int index) trueif the value at an index is a long.default booleanisOffsetDateTime(int index) trueif the value at an index is an offset date-time.default booleanisString(int index) trueif the value at an index is a string.default booleanisTable(int index) trueif the value at an index is a table.intsize()The size of the array.default voidtoJson(Appendable appendable, EnumSet<JsonOptions> options) Append a JSON representation of this array to the appendable output.default voidtoJson(Appendable appendable, JsonOptions... options) Append a JSON representation of this array to the appendable output.default StringtoJson(EnumSet<JsonOptions> options) Return a representation of this array using JSON.default StringtoJson(JsonOptions... options) Return a representation of this array using JSON.toList()Get the elements of this array as aList.default StringtoToml()Return a representation of this array using TOML, written with the default options.default voidtoToml(Appendable appendable) Append a TOML representation of this array to the appendable output, written with the default options.default voidtoToml(Appendable appendable, TomlWriteOptions options) Append a TOML representation of this array to the appendable output.default StringtoToml(TomlWriteOptions options) Return a representation of this array using TOML.
-
Method Details
-
size
int size()The size of the array.- Returns:
- The size of the array.
-
isEmpty
boolean isEmpty()trueif the array is empty.- Returns:
trueif the array is empty.
-
get
Get a value at a specified index.This is a shortcut for
entry(int), returning its value.- Parameters:
index- The array index.- Returns:
- The value.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
isString
default boolean isString(int index) trueif the value at an index is a string.- Parameters:
index- The array index.- Returns:
trueif the value at the index is a string.- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getString
Get a string at a specified index.- Parameters:
index- The array index.- Returns:
- The value.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.TomlInvalidTypeException- If the value is not a string.
-
isLong
default boolean isLong(int index) trueif the value at an index is a long.- Parameters:
index- The array index.- Returns:
trueif the value at the index is a long.- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getLong
default long getLong(int index) Get a long at a specified index.- Parameters:
index- The array index.- Returns:
- The value.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.TomlInvalidTypeException- If the value is not a long.
-
isDouble
default boolean isDouble(int index) trueif the value at an index is a double.- Parameters:
index- The array index.- Returns:
trueif the value at the index is a double.- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getDouble
default double getDouble(int index) Get a double at a specified index.- Parameters:
index- The array index.- Returns:
- The value.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.TomlInvalidTypeException- If the value is not a double.
-
isBoolean
default boolean isBoolean(int index) trueif the value at an index is a boolean.- Parameters:
index- The array index.- Returns:
trueif the value at the index is a boolean.- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getBoolean
default boolean getBoolean(int index) Get a boolean at a specified index.- Parameters:
index- The array index.- Returns:
- The value.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.TomlInvalidTypeException- If the value is not a boolean.
-
isOffsetDateTime
default boolean isOffsetDateTime(int index) trueif the value at an index is an offset date-time.- Parameters:
index- The array index.- Returns:
trueif the value at the index is an offset date-time.- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getOffsetDateTime
Get an offset date time at a specified index.- Parameters:
index- The array index.- Returns:
- The value.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.TomlInvalidTypeException- If the value is not anOffsetDateTime.
-
isLocalDateTime
default boolean isLocalDateTime(int index) trueif the value at an index is a local date-time.- Parameters:
index- The array index.- Returns:
trueif the value at the index is a local date-time.- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getLocalDateTime
Get a local date time at a specified index.- Parameters:
index- The array index.- Returns:
- The value.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.TomlInvalidTypeException- If the value is not anLocalDateTime.
-
isLocalDate
default boolean isLocalDate(int index) trueif the value at an index is a local date.- Parameters:
index- The array index.- Returns:
trueif the value at the index is a local date.- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getLocalDate
Get a local date at a specified index.- Parameters:
index- The array index.- Returns:
- The value.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.TomlInvalidTypeException- If the value is not anLocalDate.
-
isLocalTime
default boolean isLocalTime(int index) trueif the value at an index is a local time.- Parameters:
index- The array index.- Returns:
trueif the value at the index is a local time.- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getLocalTime
Get a local time at a specified index.- Parameters:
index- The array index.- Returns:
- The value.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.TomlInvalidTypeException- If the value is not anLocalTime.
-
isArray
default boolean isArray(int index) trueif the value at an index is an array.- Parameters:
index- The array index.- Returns:
trueif the value at the index is an array.- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getArray
Get an array at a specified index.- Parameters:
index- The array index.- Returns:
- The value.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.TomlInvalidTypeException- If the value is not an array.
-
isTable
default boolean isTable(int index) trueif the value at an index is a table.- Parameters:
index- The array index.- Returns:
trueif the value at the index is a table.- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
getTable
Get a table at a specified index.- Parameters:
index- The array index.- Returns:
- The value.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.TomlInvalidTypeException- If the value is not a table.
-
inputPositionOf
Get the position where a value is defined in the TOML document.This is a shortcut for
entry(int), returning its position.- Parameters:
index- The array index.- Returns:
- The input position, or
nullif the entry was not read from a document. - Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
comments
Get the comments attached to a value.Returns the comments in document order: the run directly above the value, if any, then the comment on its line, if any, so at most two, each with its
TomlComment.placement().In an array of tables, the comments on each
[[x]]header are attached to the table it opens:comments(0)for the first header, and so on.This is a shortcut for
entry(int), returning its comments.- Parameters:
index- The array index.- Returns:
- The attached comments, in document order. Unmodifiable.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
comment
Get the comment attached to a value at a placement.This is a shortcut for
entry(int), returningTomlEntry.comment(TomlComment.Placement).- Parameters:
index- The array index.placement-TomlComment.Placement.ABOVEfor the run directly above the value, orTomlComment.Placement.AFTERfor the comment on its line.- Returns:
- The comment at that placement, or
nullif there is none. - Throws:
IndexOutOfBoundsException- If the index is out of bounds.NullPointerException- Ifplacementisnull.IllegalArgumentException- IfplacementisTomlComment.Placement.UNATTACHED.
-
entry
Get the entry at an index.The entry is the
TomlEntrythatelements()holds for the index.get(int),inputPositionOf(int)andcomments(int)are shortcuts reading its value, position and comments.- Parameters:
index- The array index.- Returns:
- The entry.
- Throws:
IndexOutOfBoundsException- If the index is out of bounds.
-
elements
List<TomlElement> elements()Get the elements written in this array, in document order.Each element is a
TomlEntry, an entry of this array, or an unattachedTomlComment. The entries hold the valuesget(int)returns, in the same order. A comment is unattached when it is neither directly above a value nor on its line: a run separated by a blank line from the value below it, a run before the closing bracket, or a comment on a line with no value.- Returns:
- The elements, in document order. Unmodifiable.
-
toList
Get the elements of this array as aList.Note that this does not do a deep conversion. If this array contains tables or arrays, they will be of type
TomlTableorTomlArrayrespectively.- Returns:
- The elements of this array as a
List.
-
toJson
Return a representation of this array using JSON.- Parameters:
options- Options for the JSON encoder.- Returns:
- A JSON representation of this table.
-
toJson
Return a representation of this array using JSON.- Parameters:
options- Options for the JSON encoder.- Returns:
- A JSON representation of this table.
-
toJson
Append a JSON representation of this array to the appendable output.- Parameters:
appendable- The appendable output.options- Options for the JSON encoder.- Throws:
IOException- If an IO error occurs.
-
toJson
Append a JSON representation of this array to the appendable output.- Parameters:
appendable- The appendable output.options- Options for the JSON encoder.- Throws:
IOException- If an IO error occurs.
-
toToml
Return a representation of this array using TOML, written with the default options.An array is always written in the default style, whether or not it was parsed, keeping the literal form each of its values was parsed with.
- Returns:
- A TOML representation of this array.
- See Also:
-
toToml
Return a representation of this array using TOML.An array is always written in the default style, whether or not it was parsed; see
toToml().- Parameters:
options- The options to write with.- Returns:
- A TOML representation of this array.
- Throws:
IllegalArgumentException- If the version the options write for cannot write this array: TOML 1.0.0 and an inline table holding a comment, or text copied from a document that only TOML 1.1.0 allows; seeTomlWriteOptions.withVersion(TomlVersion).- See Also:
-
toToml
Append a TOML representation of this array to the appendable output, written with the default options.Written as
toToml()writes it.- Parameters:
appendable- The appendable output.- Throws:
IOException- If an IO error occurs.- See Also:
-
toToml
Append a TOML representation of this array to the appendable output.Written as
toToml(TomlWriteOptions)writes it.- Parameters:
appendable- The appendable output.options- The options to write with.- Throws:
IOException- If an IO error occurs.IllegalArgumentException- If the version the options write for cannot write this array: TOML 1.0.0 and an inline table holding a comment, or text copied from a document that only TOML 1.1.0 allows; seeTomlWriteOptions.withVersion(TomlVersion).- See Also:
-