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 Summary

    Modifier and Type
    Method
    Description
    static TomlValue
    binary(long value)
    An integer to be written in binary, as 0b1010; see hex(long).
    get()
    Get the value.
    default TomlArray
    Get this value as an array.
    default boolean
    Get this value as a boolean.
    default double
    Get this value as a double.
    default LocalDate
    Get this value as a local date.
    Get this value as a local date-time.
    default LocalTime
    Get this value as a local time.
    default long
    Get this value as a long.
    Get this value as an offset date-time.
    default String
    Get this value as a string.
    default TomlTable
    Get this value as a table.
    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).
    static TomlValue
    hex(long value)
    An integer to be written in hexadecimal with uppercase digits, as 0xFF.
    static TomlValue
    hexLowercase(long value)
    An integer to be written in hexadecimal with lowercase digits, as 0xff; see hex(long).
    static TomlValue
    inNotationOf(TomlValue original, long value)
    An integer to be written in the notation another integer was written in, if that notation can hold it: hexadecimal with the same case of digits, octal, binary, or decimal with its digits grouped, which are grouped in threes.
    static TomlValue
    inNotationOf(TomlValue original, String value)
    A string to be written in the notation another string was written in, if that notation can hold it: a literal or multi-line literal string.
    default boolean
    true if this value is an array.
    default boolean
    true if this value is a boolean.
    default boolean
    true if this value is a double.
    default boolean
    true if this value is a local date.
    default boolean
    true if this value is a local date-time.
    default boolean
    true if this value is a local time.
    default boolean
    true if this value is a long.
    default boolean
    true if this value is an offset date-time.
    default boolean
    true if this value is a string.
    default boolean
    true if this value is a table.
    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).
    static TomlValue
    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).
    static TomlValue
    octal(long value)
    An integer to be written in octal, as 0o755; see hex(long).
    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.
    static TomlValue
    parse(String text, TomlVersion version)
    Parse the text of one value, written as it is after the = of a key = value line.

    Methods inherited from interface org.tomlj.TomlElement

    position
  • 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.
    • inNotationOf

      static TomlValue inNotationOf(TomlValue original, long value)
      An integer to be written in the notation another integer was written in, if that notation can hold it: hexadecimal with the same case of digits, octal, binary, or decimal with its digits grouped, which are grouped in threes.

      This keeps the notation of a value that is replaced. Where a document has mask = 0xFF, doc.set("mask", TomlValue.inNotationOf(doc.entry("mask").value(), 171)) writes mask = 0xAB, where doc.set("mask", 171) writes mask = 171.

      The value is written in the default notation, as a long is, if original is not an integer, was written in none of these notations, or was written in one that cannot hold value, such as hexadecimal for a negative integer. A value read from a document parsed without its source (TomlParseOptions.withoutSource()) has no record of its notation.

      Parameters:
      original - The value whose notation to write value in.
      value - The integer.
      Returns:
      The value.
      Throws:
      NullPointerException - If original is null.
      See Also:
    • inNotationOf

      static TomlValue inNotationOf(TomlValue original, String value)
      A string to be written in the notation another string was written in, if that notation can hold it: a literal or multi-line literal string.

      This keeps the notation of a value that is replaced, as inNotationOf(TomlValue, long) does for an integer. Where a document has path = 'C:\Users', doc.set("path", TomlValue.inNotationOf(doc.entry("path").value(), "D:\\Data")) writes path = 'D:\Data'.

      The value is written in the default notation, as a String is, if original is not a string, was written in neither of these notations, or was written in one that cannot hold value, such as a literal string for a string with an apostrophe.

      Parameters:
      original - The value whose notation to write value in.
      value - The string.
      Returns:
      The value.
      Throws:
      NullPointerException - If original or value is null.
      IllegalArgumentException - If value contains an unpaired surrogate.
      See Also:
    • 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.