Package org.tomlj

Interface TomlArray

All Known Subinterfaces:
MutableTomlArray

public interface TomlArray
An array of TOML values.

An array that can be edited is a MutableTomlArray; the arrays of a parse result are.

  • Method Summary

    Modifier and Type
    Method
    Description
    default @Nullable TomlComment
    comment(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.
    Get the elements written in this array, in document order.
    entry(int index)
    Get the entry at an index.
    default Object
    get(int index)
    Get a value at a specified index.
    default TomlArray
    getArray(int index)
    Get an array at a specified index.
    default boolean
    getBoolean(int index)
    Get a boolean at a specified index.
    default double
    getDouble(int index)
    Get a double at a specified index.
    default LocalDate
    getLocalDate(int index)
    Get a local date at a specified index.
    getLocalDateTime(int index)
    Get a local date time at a specified index.
    default LocalTime
    getLocalTime(int index)
    Get a local time at a specified index.
    default long
    getLong(int index)
    Get a long at a specified index.
    getOffsetDateTime(int index)
    Get an offset date time at a specified index.
    default String
    getString(int index)
    Get a string at a specified index.
    default TomlTable
    getTable(int index)
    Get a table at a specified index.
    default @Nullable TomlPosition
    inputPositionOf(int index)
    Get the position where a value is defined in the TOML document.
    default boolean
    isArray(int index)
    true if the value at an index is an array.
    default boolean
    isBoolean(int index)
    true if the value at an index is a boolean.
    default boolean
    isDouble(int index)
    true if the value at an index is a double.
    boolean
    true if the array is empty.
    default boolean
    isLocalDate(int index)
    true if the value at an index is a local date.
    default boolean
    isLocalDateTime(int index)
    true if the value at an index is a local date-time.
    default boolean
    isLocalTime(int index)
    true if the value at an index is a local time.
    default boolean
    isLong(int index)
    true if the value at an index is a long.
    default boolean
    isOffsetDateTime(int index)
    true if the value at an index is an offset date-time.
    default boolean
    isString(int index)
    true if the value at an index is a string.
    default boolean
    isTable(int index)
    true if the value at an index is a table.
    int
    The size of the array.
    default void
    toJson(Appendable appendable, EnumSet<JsonOptions> options)
    Append a JSON representation of this array to the appendable output.
    default void
    toJson(Appendable appendable, JsonOptions... options)
    Append a JSON representation of this array to the appendable output.
    default String
    Return a representation of this array using JSON.
    default String
    toJson(JsonOptions... options)
    Return a representation of this array using JSON.
    Get the elements of this array as a List.
    default String
    Return a representation of this array using TOML, written with the default options.
    default void
    toToml(Appendable appendable)
    Append a TOML representation of this array to the appendable output, written with the default options.
    default void
    toToml(Appendable appendable, TomlWriteOptions options)
    Append a TOML representation of this array to the appendable output.
    default String
    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()
      true if the array is empty.
      Returns:
      true if the array is empty.
    • get

      default Object get(int index)
      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)
      true if the value at an index is a string.
      Parameters:
      index - The array index.
      Returns:
      true if the value at the index is a string.
      Throws:
      IndexOutOfBoundsException - If the index is out of bounds.
    • getString

      default String getString(int index)
      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)
      true if the value at an index is a long.
      Parameters:
      index - The array index.
      Returns:
      true if 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)
      true if the value at an index is a double.
      Parameters:
      index - The array index.
      Returns:
      true if 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)
      true if the value at an index is a boolean.
      Parameters:
      index - The array index.
      Returns:
      true if 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)
      true if the value at an index is an offset date-time.
      Parameters:
      index - The array index.
      Returns:
      true if the value at the index is an offset date-time.
      Throws:
      IndexOutOfBoundsException - If the index is out of bounds.
    • getOffsetDateTime

      default OffsetDateTime getOffsetDateTime(int index)
      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 an OffsetDateTime.
    • isLocalDateTime

      default boolean isLocalDateTime(int index)
      true if the value at an index is a local date-time.
      Parameters:
      index - The array index.
      Returns:
      true if the value at the index is a local date-time.
      Throws:
      IndexOutOfBoundsException - If the index is out of bounds.
    • getLocalDateTime

      default LocalDateTime getLocalDateTime(int index)
      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 an LocalDateTime.
    • isLocalDate

      default boolean isLocalDate(int index)
      true if the value at an index is a local date.
      Parameters:
      index - The array index.
      Returns:
      true if the value at the index is a local date.
      Throws:
      IndexOutOfBoundsException - If the index is out of bounds.
    • getLocalDate

      default LocalDate getLocalDate(int index)
      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 an LocalDate.
    • isLocalTime

      default boolean isLocalTime(int index)
      true if the value at an index is a local time.
      Parameters:
      index - The array index.
      Returns:
      true if the value at the index is a local time.
      Throws:
      IndexOutOfBoundsException - If the index is out of bounds.
    • getLocalTime

      default LocalTime getLocalTime(int index)
      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 an LocalTime.
    • isArray

      default boolean isArray(int index)
      true if the value at an index is an array.
      Parameters:
      index - The array index.
      Returns:
      true if the value at the index is an array.
      Throws:
      IndexOutOfBoundsException - If the index is out of bounds.
    • getArray

      default TomlArray getArray(int index)
      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)
      true if the value at an index is a table.
      Parameters:
      index - The array index.
      Returns:
      true if the value at the index is a table.
      Throws:
      IndexOutOfBoundsException - If the index is out of bounds.
    • getTable

      default TomlTable getTable(int index)
      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

      default @Nullable TomlPosition inputPositionOf(int index)
      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 null if the entry was not read from a document.
      Throws:
      IndexOutOfBoundsException - If the index is out of bounds.
    • comments

      default List<TomlComment> comments(int index)
      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

      default @Nullable TomlComment comment(int index, TomlComment.Placement placement)
      Get the comment attached to a value at a placement.

      This is a shortcut for entry(int), returning TomlEntry.comment(TomlComment.Placement).

      Parameters:
      index - The array index.
      placement - TomlComment.Placement.ABOVE for the run directly above the value, or TomlComment.Placement.AFTER for the comment on its line.
      Returns:
      The comment at that placement, or null if there is none.
      Throws:
      IndexOutOfBoundsException - If the index is out of bounds.
      NullPointerException - If placement is null.
      IllegalArgumentException - If placement is TomlComment.Placement.UNATTACHED.
    • entry

      TomlEntry entry(int index)
      Get the entry at an index.

      The entry is the TomlEntry that elements() holds for the index. get(int), inputPositionOf(int) and comments(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 unattached TomlComment. The entries hold the values get(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

      List<Object> toList()
      Get the elements of this array as a List.

      Note that this does not do a deep conversion. If this array contains tables or arrays, they will be of type TomlTable or TomlArray respectively.

      Returns:
      The elements of this array as a List.
    • toJson

      default String toJson(JsonOptions... options)
      Return a representation of this array using JSON.
      Parameters:
      options - Options for the JSON encoder.
      Returns:
      A JSON representation of this table.
    • toJson

      default String toJson(EnumSet<JsonOptions> options)
      Return a representation of this array using JSON.
      Parameters:
      options - Options for the JSON encoder.
      Returns:
      A JSON representation of this table.
    • toJson

      default void toJson(Appendable appendable, JsonOptions... options) throws IOException
      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

      default void toJson(Appendable appendable, EnumSet<JsonOptions> options) throws IOException
      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

      default String 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

      default String toToml(TomlWriteOptions options)
      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; see TomlWriteOptions.withVersion(TomlVersion).
      See Also:
    • toToml

      default void toToml(Appendable appendable) throws IOException
      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

      default void toToml(Appendable appendable, TomlWriteOptions options) throws IOException
      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; see TomlWriteOptions.withVersion(TomlVersion).
      See Also: