Package org.tomlj

Interface TomlValue

All Superinterfaces:
TomlElement

public interface TomlValue extends TomlElement
A value written in a document: under a key in a table, or in an array.

A table or array is itself the value, so a TomlTable or TomlArray read from a document is also a TomlValue. The unattached comments written inside it are among its TomlTable.elements() or TomlArray.elements(). A value never carries comments of its own: the comments written around it belong to the entry that holds it, read through TomlEntry.comments().

  • Method Details

    • parse

      static TomlValue parse(String text)
      Parse the text of one value, written as it is after the = of a key = value line, in the latest version of TOML.
      Parameters:
      text - The value, e.g. 0xFF, 'C:\path' or { a = 1 }.
      Returns:
      The value, which keeps the notation it was written in; see parse(String, TomlVersion).
      Throws:
      NullPointerException - If text is null.
      IllegalArgumentException - If text is not one TOML value.
    • parse

      static TomlValue parse(String text, TomlVersion version)
      Parse the text of one value, written as it is after the = of a key = value line.

      The value keeps the notation it was written in. Stored in a table or an array through the editing API, it is written with the text it was parsed from, as a value read from a document is, unless the document is written keeping nothing (TomlWriteOptions.Keep.NOTHING); an inline table is written as an inline table, and an array of tables as an array, rather than under [x] or [[x]] headers. Text that only TOML 1.1.0 allows is not written for TOML 1.0.0; see TomlWriteOptions.withVersion(TomlVersion).

      A comment or a line break before or after the value is rejected. A comment inside an inline table or an array is part of the value and is kept.

      Parameters:
      text - The value, e.g. 0xFF, 'C:\path' or { a = 1 }.
      version - The version of TOML the value is written in.
      Returns:
      The value.
      Throws:
      NullPointerException - If text or version is null.
      IllegalArgumentException - If text is not one TOML value.
    • hex

      static TomlValue hex(long value)
      An integer to be written in hexadecimal with uppercase digits, as 0xFF.

      The value carries the notation with it: stored in a table or an array through the editing API, it is written in that notation unless the document is written keeping nothing (TomlWriteOptions.Keep.NOTHING). parse(String) gives a value any notation TOML has.

      Parameters:
      value - The integer.
      Returns:
      The value.
      Throws:
      IllegalArgumentException - If value is negative, since TOML writes no sign before 0x.
      See Also:
    • hexLowercase

      static TomlValue hexLowercase(long value)
      An integer to be written in hexadecimal with lowercase digits, as 0xff; see hex(long).
      Parameters:
      value - The integer.
      Returns:
      The value.
      Throws:
      IllegalArgumentException - If value is negative, since TOML writes no sign before 0x.
    • octal

      static TomlValue octal(long value)
      An integer to be written in octal, as 0o755; see hex(long).
      Parameters:
      value - The integer.
      Returns:
      The value.
      Throws:
      IllegalArgumentException - If value is negative, since TOML writes no sign before 0o.
    • binary

      static TomlValue binary(long value)
      An integer to be written in binary, as 0b1010; see hex(long).
      Parameters:
      value - The integer.
      Returns:
      The value.
      Throws:
      IllegalArgumentException - If value is negative, since TOML writes no sign before 0b.
    • grouped

      static TomlValue grouped(long value)
      An integer to be written in decimal with its digits grouped in threes, as 1_000_000; see hex(long).
      Parameters:
      value - The integer.
      Returns:
      The value.
    • literal

      static TomlValue literal(String value)
      A string to be written as a literal string, between apostrophes with nothing escaped, as 'C:\Users'; see hex(long).
      Parameters:
      value - The string.
      Returns:
      The value.
      Throws:
      NullPointerException - If value is null.
      IllegalArgumentException - If value holds an apostrophe, a newline or a control character other than tab, none of which a literal string can hold, or an unpaired surrogate.
    • multilineLiteral

      static TomlValue multilineLiteral(String value)
      A string to be written as a multi-line literal string, between triple apostrophes with nothing escaped, its newlines written as line breaks; see hex(long).
      Parameters:
      value - The string.
      Returns:
      The value.
      Throws:
      NullPointerException - If value is null.
      IllegalArgumentException - If value holds three apostrophes in a row, or a control character other than tab and newline, none of which a multi-line literal string can hold, or an unpaired surrogate.
    • get

      Object get()
      Get the value.
      Returns:
      The value: a String, Long, Double, Boolean, date/time, TomlTable or TomlArray.
    • isString

      default boolean isString()
      true if this value is a string.
      Returns:
      true if this value is a string.
    • getString

      default String getString()
      Get this value as a string.
      Returns:
      The value.
      Throws:
      TomlInvalidTypeException - If the value is not a string.
    • isLong

      default boolean isLong()
      true if this value is a long.
      Returns:
      true if this value is a long.
    • getLong

      default long getLong()
      Get this value as a long.
      Returns:
      The value.
      Throws:
      TomlInvalidTypeException - If the value is not a long.
    • isDouble

      default boolean isDouble()
      true if this value is a double.
      Returns:
      true if this value is a double.
    • getDouble

      default double getDouble()
      Get this value as a double.
      Returns:
      The value.
      Throws:
      TomlInvalidTypeException - If the value is not a double.
    • isBoolean

      default boolean isBoolean()
      true if this value is a boolean.
      Returns:
      true if this value is a boolean.
    • getBoolean

      default boolean getBoolean()
      Get this value as a boolean.
      Returns:
      The value.
      Throws:
      TomlInvalidTypeException - If the value is not a boolean.
    • isOffsetDateTime

      default boolean isOffsetDateTime()
      true if this value is an offset date-time.
      Returns:
      true if this value is an offset date-time.
    • getOffsetDateTime

      default OffsetDateTime getOffsetDateTime()
      Get this value as an offset date-time.
      Returns:
      The value.
      Throws:
      TomlInvalidTypeException - If the value is not an offset date-time.
    • isLocalDateTime

      default boolean isLocalDateTime()
      true if this value is a local date-time.
      Returns:
      true if this value is a local date-time.
    • getLocalDateTime

      default LocalDateTime getLocalDateTime()
      Get this value as a local date-time.
      Returns:
      The value.
      Throws:
      TomlInvalidTypeException - If the value is not a local date-time.
    • isLocalDate

      default boolean isLocalDate()
      true if this value is a local date.
      Returns:
      true if this value is a local date.
    • getLocalDate

      default LocalDate getLocalDate()
      Get this value as a local date.
      Returns:
      The value.
      Throws:
      TomlInvalidTypeException - If the value is not a local date.
    • isLocalTime

      default boolean isLocalTime()
      true if this value is a local time.
      Returns:
      true if this value is a local time.
    • getLocalTime

      default LocalTime getLocalTime()
      Get this value as a local time.
      Returns:
      The value.
      Throws:
      TomlInvalidTypeException - If the value is not a local time.
    • isArray

      default boolean isArray()
      true if this value is an array.
      Returns:
      true if this value is an array.
    • getArray

      default TomlArray getArray()
      Get this value as an array.
      Returns:
      The value.
      Throws:
      TomlInvalidTypeException - If the value is not an array.
    • isTable

      default boolean isTable()
      true if this value is a table.
      Returns:
      true if this value is a table.
    • getTable

      default TomlTable getTable()
      Get this value as a table.
      Returns:
      The value.
      Throws:
      TomlInvalidTypeException - If the value is not a table.