Record Class TomlTable

java.lang.Object
java.lang.Record
be.imgn.toml.TomlTable
Record Components:
entries - the entries, which keep their iteration order; the map is copied
All Implemented Interfaces:
TomlValue

public record TomlTable(Map<String, TomlValue> entries) extends Record implements TomlValue

A TOML table: keys mapped to values, in the order the keys were given or appeared in the document.

Besides entries(), a table looks its values up by a TOML key, which can be dotted and quoted as in a document. get("server.port") is the value of the key port in the table server, and get("site.\"example.com\"") the value of the key example.com in the table site. The typed getters, such as getString(String), also check the type of the value.

Two tables are equal when they have the same entries, whatever their order.

Since:
0.1.0
  • Constructor Details

  • Method Details

    • builder

      public static TomlTable.Builder builder()
      Returns a builder of tables, which keeps the entries in the order they are put.
      Returns:
      a new builder
    • toBuilder

      public TomlTable.Builder toBuilder()
      Returns a builder that starts with the entries of this table, in their order. The builder does not change this table.
      Returns:
      a new builder
    • get

      public Optional<TomlValue> get(String key)
      Returns the value of a key.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key, or empty if this table has none
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
    • getTable

      public TomlTable getTable(String key)
      Returns the table that is the value of a key.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
      NoSuchElementException - if this table has no value for key
      ClassCastException - if the value of key is not a table
    • getArray

      public TomlArray getArray(String key)
      Returns the array that is the value of a key.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
      NoSuchElementException - if this table has no value for key
      ClassCastException - if the value of key is not an array
    • getString

      public String getString(String key)
      Returns the string that is the value of a key.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
      NoSuchElementException - if this table has no value for key
      ClassCastException - if the value of key is not a string
    • getLong

      public long getLong(String key)
      Returns the integer that is the value of a key.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
      NoSuchElementException - if this table has no value for key
      ClassCastException - if the value of key is not an integer
    • getInt

      public int getInt(String key)
      Returns the integer that is the value of a key, as an int.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
      NoSuchElementException - if this table has no value for key
      ClassCastException - if the value of key is not an integer
      ArithmeticException - if the value of key is out of the range of int
    • getDouble

      public double getDouble(String key)
      Returns the float that is the value of a key.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
      NoSuchElementException - if this table has no value for key
      ClassCastException - if the value of key is not a float
    • getBoolean

      public boolean getBoolean(String key)
      Returns the boolean that is the value of a key.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
      NoSuchElementException - if this table has no value for key
      ClassCastException - if the value of key is not a boolean
    • getOffsetDateTime

      public OffsetDateTime getOffsetDateTime(String key)
      Returns the offset date-time that is the value of a key.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
      NoSuchElementException - if this table has no value for key
      ClassCastException - if the value of key is not an offset date-time
    • getLocalDateTime

      public LocalDateTime getLocalDateTime(String key)
      Returns the local date-time that is the value of a key.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
      NoSuchElementException - if this table has no value for key
      ClassCastException - if the value of key is not a local date-time
    • getLocalDate

      public LocalDate getLocalDate(String key)
      Returns the local date that is the value of a key.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
      NoSuchElementException - if this table has no value for key
      ClassCastException - if the value of key is not a local date
    • getLocalTime

      public LocalTime getLocalTime(String key)
      Returns the local time that is the value of a key.
      Parameters:
      key - a key, which can be dotted and quoted as in a document
      Returns:
      the value of key
      Throws:
      NullPointerException - if key is null
      IllegalArgumentException - if key is not a valid TOML key
      NoSuchElementException - if this table has no value for key
      ClassCastException - if the value of key is not a local time
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • entries

      public Map<String, TomlValue> entries()
      Returns the value of the entries record component.
      Returns:
      the value of the entries record component