Interface TomlTable
- All Known Subinterfaces:
MutableTomlTable,TomlParseResult
Values can be addressed in two ways. Methods that take a String interpret it as a dotted key using
TOML key syntax, exactly as it would appear in a document: "server.port" names the port entry within
the server table, and any key containing characters other than A-Z, a-z, 0-9,
_ and - must be quoted, e.g. "\"@key\".value". Methods that take a List<String>
interpret each element as a literal key, with no quoting or escaping required.
Consequently, the raw key names returned by keySet() and entrySet() can be used with the
List<String> methods (e.g. get(Collections.singletonList(key))), but not directly with the
String methods unless the key is a bare key. The keys returned by dottedKeySet() and
dottedEntrySet() are already quoted where necessary and can be passed to the String methods.
Toml.joinKeyPath(List) converts a key path into a dotted key.
The key sets, the entry sets and toMap() list the keys in the order elements() lists their entries.
The dotted and path sets list the paths within a table where the table's key is, after the table's own path when
tables are included.
The comments of a document are kept, and are read from the table or array they were written in; see
TomlComment.
A table that can be edited is a MutableTomlTable; a parse result is one.
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> TBind this table to a Java type, with the default options.default <T> Tas(Class<T> type, TomlBindOptions options) Bind this table to a Java type.default <T> Tas(GenericType<T> type) Bind this table to a generic Java type, with the default options.default <T> Tas(GenericType<T> type, TomlBindOptions options) Bind this table to a generic Java type.default @Nullable TomlCommentcomment(String dottedKey, TomlComment.Placement placement) Get the comment attached to a key at a placement.default @Nullable TomlCommentcomment(List<String> path, TomlComment.Placement placement) Get the comment attached to a key at a placement.default List<TomlComment> Get the comments attached to a key.default List<TomlComment> Get the comments attached to a key.default booleanCheck if a key was set in the TOML document.default booleanCheck if a key was set in the TOML document.Get all the dotted entries of this table.dottedEntrySet(boolean includeTables) Get all the dotted entries of this table.Get all the dotted keys of this table.dottedKeySet(boolean includeTables) Get all the dotted keys of this table.elements()Get the elements written in this table, in document order.default @Nullable TomlKeyValueGet the entry for a key.@Nullable TomlKeyValueGet the entry for a key.Get all the entries in this table.entryPathSet(boolean includeTables) Get all the entries in this table.entrySet()Get the entries of this table.default @Nullable ObjectGet a value from the TOML document.default @Nullable ObjectGet a value from the TOML document.default @Nullable TomlArrayGet an array from the TOML document.default @Nullable TomlArrayGet an array from the TOML document.default TomlArraygetArrayOrEmpty(String dottedKey) Get an array from the TOML document.default TomlArraygetArrayOrEmpty(List<String> path) Get an array from the TOML document.default @Nullable BooleangetBoolean(String dottedKey) Get a boolean from the TOML document.default booleangetBoolean(String dottedKey, BooleanSupplier defaultValue) Get a boolean from the TOML document, or return a default.default @Nullable BooleangetBoolean(List<String> path) Get a boolean from the TOML document.default booleangetBoolean(List<String> path, BooleanSupplier defaultValue) Get a boolean from the TOML document, or return a default.default @Nullable DoubleGet a double from the TOML document.default doublegetDouble(String dottedKey, DoubleSupplier defaultValue) Get a double from the TOML document, or return a default.default @Nullable DoubleGet a double from the TOML document.default doublegetDouble(List<String> path, DoubleSupplier defaultValue) Get a double from the TOML document, or return a default.default @Nullable LocalDategetLocalDate(String dottedKey) Get a local date from the TOML document.default LocalDategetLocalDate(String dottedKey, Supplier<LocalDate> defaultValue) Get a local date from the TOML document, or return a default.default @Nullable LocalDategetLocalDate(List<String> path) Get a local date from the TOML document.default LocalDategetLocalDate(List<String> path, Supplier<LocalDate> defaultValue) Get a local date from the TOML document, or return a default.default @Nullable LocalDateTimegetLocalDateTime(String dottedKey) Get a local date time from the TOML document.default LocalDateTimegetLocalDateTime(String dottedKey, Supplier<LocalDateTime> defaultValue) Get a local date time from the TOML document, or return a default.default @Nullable LocalDateTimegetLocalDateTime(List<String> path) Get a local date time from the TOML document.default LocalDateTimegetLocalDateTime(List<String> path, Supplier<LocalDateTime> defaultValue) Get a local date time from the TOML document, or return a default.default @Nullable LocalTimegetLocalTime(String dottedKey) Get a local time from the TOML document.default LocalTimegetLocalTime(String dottedKey, Supplier<LocalTime> defaultValue) Get a local time from the TOML document, or return a default.default @Nullable LocalTimegetLocalTime(List<String> path) Get a local time from the TOML document.default LocalTimegetLocalTime(List<String> path, Supplier<LocalTime> defaultValue) Get a local time from the TOML document, or return a default.default @Nullable LongGet a long from the TOML document.default longgetLong(String dottedKey, LongSupplier defaultValue) Get a long from the TOML document, or return a default.default @Nullable LongGet a long from the TOML document.default longgetLong(List<String> path, LongSupplier defaultValue) Get a long from the TOML document, or return a default.default @Nullable OffsetDateTimegetOffsetDateTime(String dottedKey) Get an offset date time from the TOML document.default OffsetDateTimegetOffsetDateTime(String dottedKey, Supplier<OffsetDateTime> defaultValue) Get an offset date time from the TOML document, or return a default.default @Nullable OffsetDateTimegetOffsetDateTime(List<String> path) Get an offset date time from the TOML document.default OffsetDateTimegetOffsetDateTime(List<String> path, Supplier<OffsetDateTime> defaultValue) Get an offset date time from the TOML document, or return a default.default @Nullable StringGet a string from the TOML document.default StringGet a string from the TOML document, or return a default.default @Nullable StringGet a string from the TOML document.default StringGet a string from the TOML document, or return a default.default @Nullable TomlTableGet a table from the TOML document.default @Nullable TomlTableGet a table from the TOML document.default TomlTablegetTableOrEmpty(String dottedKey) Get a table from the TOML document.default TomlTablegetTableOrEmpty(List<String> path) Get a table from the TOML document.default @Nullable TomlPositioninputPositionOf(String dottedKey) Get the position where a key is defined in the TOML document.@Nullable TomlPositioninputPositionOf(List<String> path) Get the position where a key is defined in the TOML document.default booleanCheck if a value in the TOML document is an array.default booleanCheck if a value in the TOML document is an array.default booleanCheck if a value in the TOML document is a boolean.default booleanCheck if a value in the TOML document is a boolean.default booleanCheck if a value in the TOML document is a double.default booleanCheck if a value in the TOML document is a double.booleanisEmpty()trueif there are no entries in this table.default booleanisLocalDate(String dottedKey) Check if a value in the TOML document is aLocalDate.default booleanisLocalDate(List<String> path) Check if a value in the TOML document is aLocalDate.default booleanisLocalDateTime(String dottedKey) Check if a value in the TOML document is aLocalDateTime.default booleanisLocalDateTime(List<String> path) Check if a value in the TOML document is aLocalDateTime.default booleanisLocalTime(String dottedKey) Check if a value in the TOML document is aLocalTime.default booleanisLocalTime(List<String> path) Check if a value in the TOML document is aLocalTime.default booleanCheck if a value in the TOML document is a long.default booleanCheck if a value in the TOML document is a long.default booleanisOffsetDateTime(String dottedKey) Check if a value in the TOML document is anOffsetDateTime.default booleanisOffsetDateTime(List<String> path) Check if a value in the TOML document is anOffsetDateTime.default booleanCheck if a value in the TOML document is a string.default booleanCheck if a value in the TOML document is a string.default booleanCheck if a value in the TOML document is a table.default booleanCheck if a value in the TOML document is a table.Get all the paths in this table.keyPathSet(boolean includeTables) Get all the paths in this table.keySet()Get the keys of this table.intsize()Return the number of entries in tis table.default voidtoJson(Appendable appendable, EnumSet<JsonOptions> options) Append a JSON representation of this table to the appendable output.default voidtoJson(Appendable appendable, JsonOptions... options) Append a JSON representation of this table to the appendable output.default StringtoJson(EnumSet<JsonOptions> options) Return a representation of this table using JSON.default StringtoJson(JsonOptions... options) Return a representation of this table using JSON.toMap()Get the entries of this table as aMap.default StringtoToml()Return a representation of this table using TOML, written with the default options.default voidtoToml(Appendable appendable) Append a TOML representation of this table to the appendable output, written with the default options.default voidtoToml(Appendable appendable, TomlWriteOptions options) Append a TOML representation of this table to the appendable output.default StringtoToml(TomlWriteOptions options) Return a representation of this table using TOML.
-
Method Details
-
size
int size()Return the number of entries in tis table.- Returns:
- The number of entries in tis table.
-
isEmpty
boolean isEmpty()trueif there are no entries in this table.- Returns:
trueif there are no entries in this table.
-
contains
Check if a key was set in the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.port").- Returns:
trueif the key was set in the TOML document.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
contains
Check if a key was set in the TOML document.- Parameters:
path- The key path.- Returns:
trueif the key was set in the TOML document.
-
keySet
Get the keys of this table.The returned set contains only immediate keys to this table, and not dotted keys or key paths. For a complete view of keys available in the TOML document, use
dottedKeySet()orkeyPathSet().The keys are returned as raw names, without quoting. To look up a value by one of these keys, use a
List<String>method such asget(List), or quote it withToml.joinKeyPath(List)before passing it to aStringmethod such asget(String).- Returns:
- A set containing the keys of this table.
-
dottedKeySet
Get all the dotted keys of this table.Paths to intermediary and empty tables are not returned. To include these, use
dottedKeySet(boolean).- Returns:
- A set containing all the dotted keys of this table.
-
dottedKeySet
Get all the dotted keys of this table.- Parameters:
includeTables- Iftrue, also include paths to intermediary and empty tables.- Returns:
- A set containing all the dotted keys of this table.
-
keyPathSet
Get all the paths in this table.Paths to intermediary and empty tables are not returned. To include these, use
keyPathSet(boolean).- Returns:
- A set containing all the key paths of this table.
-
keyPathSet
Get all the paths in this table.- Parameters:
includeTables- Iftrue, also include paths to intermediary and empty tables.- Returns:
- A set containing all the key paths of this table.
-
entrySet
Get the entries of this table.The returned set contains only immediate entries of this table, and not entries with dotted keys or key paths. For a complete view of all entries available in the TOML document, use
dottedEntrySet()orentryPathSet().The entry keys are raw names, without quoting. See
keySet()for how to use them in lookups.- Returns:
- A set containing the immediate entries of this table.
-
dottedEntrySet
Get all the dotted entries of this table.Paths to intermediary and empty tables are not returned. To include these, use
dottedEntrySet(boolean).- Returns:
- A set containing all the entries of this table.
-
dottedEntrySet
Get all the dotted entries of this table.- Parameters:
includeTables- Iftrue, also include paths to intermediary and empty tables.- Returns:
- A set containing all the entries of this table.
-
entryPathSet
Get all the entries in this table.Paths to intermediary and empty tables are not returned. To include these, use
entryPathSet(boolean).- Returns:
- A set containing all the entries of this table.
-
entryPathSet
Get all the entries in this table.- Parameters:
includeTables- Iftrue, also include entries in intermediary and empty tables.- Returns:
- A set containing all the entries of this table.
-
get
Get a value from the TOML document.The key is parsed using TOML key syntax, so keys containing characters other than
A-Z,a-z,0-9,_and-must be quoted (e.g."\"@key\""). To look up a raw key name without quoting, such as one returned bykeySet(), useget(List)instead.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If any element of the path preceding the final key is not a table.
-
get
Get a value from the TOML document.This is a shortcut for
entry(List), returning its value.- Parameters:
path- The key path.- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
TomlInvalidTypeException- If any element of the path preceding the final key is not a table.
-
isString
Check if a value in the TOML document is a string.- Parameters:
dottedKey- A dotted key (e.g."server.address.hostname").- Returns:
trueif the value can be obtained as a string.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
isString
Check if a value in the TOML document is a string.- Parameters:
path- The key path.- Returns:
trueif the value can be obtained as a string.
-
getString
Get a string from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.address.hostname").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not a string, or any element of the path preceding the final key is not a table.
-
getString
Get a string from the TOML document.- Parameters:
path- A dotted key (e.g."server.address.hostname").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
TomlInvalidTypeException- If the value is present but not a string, or any element of the path preceding the final key is not a table.
-
getString
Get a string from the TOML document, or return a default.- Parameters:
dottedKey- A dotted key (e.g."server.address.hostname").defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not a string, or any element of the path preceding the final key is not a table.
-
getString
Get a string from the TOML document, or return a default.- Parameters:
path- The key path.defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
TomlInvalidTypeException- If the value is present but not a string, or any element of the path preceding the final key is not a table.
-
isLong
Check if a value in the TOML document is a long.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
trueif the value can be obtained as a long.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
isLong
Check if a value in the TOML document is a long.- Parameters:
path- The key path.- Returns:
trueif the value can be obtained as a long.
-
getLong
Get a long from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not a long, or any element of the path preceding the final key is not a table.
-
getLong
Get a long from the TOML document.- Parameters:
path- The key path.- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
TomlInvalidTypeException- If the value is present but not a long, or any element of the path preceding the final key is not a table.
-
getLong
Get a long from the TOML document, or return a default.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not a long, or any element of the path preceding the final key is not a table.
-
getLong
Get a long from the TOML document, or return a default.- Parameters:
path- The key path.defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
TomlInvalidTypeException- If the value is present but not a long, or any element of the path preceding the final key is not a table.
-
isDouble
Check if a value in the TOML document is a double.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
trueif the value can be obtained as a double.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
isDouble
Check if a value in the TOML document is a double.- Parameters:
path- The key path.- Returns:
trueif the value can be obtained as a double.
-
getDouble
Get a double from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not a double, or any element of the path preceding the final key is not a table.
-
getDouble
Get a double from the TOML document.- Parameters:
path- A dotted key.- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
TomlInvalidTypeException- If the value is present but not a double, or any element of the path preceding the final key is not a table.
-
getDouble
Get a double from the TOML document, or return a default.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not a double, or any element of the path preceding the final key is not a table.
-
getDouble
Get a double from the TOML document, or return a default.- Parameters:
path- The key path.defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
TomlInvalidTypeException- If the value is present but not a double, or any element of the path preceding the final key is not a table.
-
isBoolean
Check if a value in the TOML document is a boolean.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
trueif the value can be obtained as a boolean.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
isBoolean
Check if a value in the TOML document is a boolean.- Parameters:
path- The key path.- Returns:
trueif the value can be obtained as a boolean.
-
getBoolean
Get a boolean from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not a boolean, or any element of the path preceding the final key is not a table.
-
getBoolean
Get a boolean from the TOML document.- Parameters:
path- The key path.- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
TomlInvalidTypeException- If the value is present but not a boolean, or any element of the path preceding the final key is not a table.
-
getBoolean
Get a boolean from the TOML document, or return a default.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not a boolean, or any element of the path preceding the final key is not a table.
-
getBoolean
Get a boolean from the TOML document, or return a default.- Parameters:
path- The key path.defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
TomlInvalidTypeException- If the value is present but not a boolean, or any element of the path preceding the final key is not a table.
-
isOffsetDateTime
Check if a value in the TOML document is anOffsetDateTime.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
trueif the value can be obtained as anOffsetDateTime.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
isOffsetDateTime
Check if a value in the TOML document is anOffsetDateTime.- Parameters:
path- The key path.- Returns:
trueif the value can be obtained as anOffsetDateTime.
-
getOffsetDateTime
Get an offset date time from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not anOffsetDateTime, or any element of the path preceding the final key is not a table.
-
getOffsetDateTime
Get an offset date time from the TOML document.- Parameters:
path- The key path.- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
TomlInvalidTypeException- If the value is present but not anOffsetDateTime, or any element of the path preceding the final key is not a table.
-
getOffsetDateTime
Get an offset date time from the TOML document, or return a default.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not anOffsetDateTime, or any element of the path preceding the final key is not a table.
-
getOffsetDateTime
Get an offset date time from the TOML document, or return a default.- Parameters:
path- The key path.defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
TomlInvalidTypeException- If the value is present but not anOffsetDateTime, or any element of the path preceding the final key is not a table.
-
isLocalDateTime
Check if a value in the TOML document is aLocalDateTime.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
trueif the value can be obtained as aLocalDateTime.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
isLocalDateTime
Check if a value in the TOML document is aLocalDateTime.- Parameters:
path- The key path.- Returns:
trueif the value can be obtained as aLocalDateTime.
-
getLocalDateTime
Get a local date time from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not aLocalDateTime, or any element of the path preceding the final key is not a table.
-
getLocalDateTime
Get a local date time from the TOML document.- Parameters:
path- The key path.- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
TomlInvalidTypeException- If the value is present but not aLocalDateTime, or any element of the path preceding the final key is not a table.
-
getLocalDateTime
Get a local date time from the TOML document, or return a default.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not aLocalDateTime, or any element of the path preceding the final key is not a table.
-
getLocalDateTime
Get a local date time from the TOML document, or return a default.- Parameters:
path- The key path.defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
TomlInvalidTypeException- If the value is present but not aLocalDateTime, or any element of the path preceding the final key is not a table.
-
isLocalDate
Check if a value in the TOML document is aLocalDate.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
trueif the value can be obtained as aLocalDate.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
isLocalDate
Check if a value in the TOML document is aLocalDate.- Parameters:
path- The key path.- Returns:
trueif the value can be obtained as aLocalDate.
-
getLocalDate
Get a local date from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not aLocalDate, or any element of the path preceding the final key is not a table.
-
getLocalDate
Get a local date from the TOML document.- Parameters:
path- The key path.- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
TomlInvalidTypeException- If the value is present but not aLocalDate, or any element of the path preceding the final key is not a table.
-
getLocalDate
Get a local date from the TOML document, or return a default.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not aLocalDate, or any element of the path preceding the final key is not a table.
-
getLocalDate
Get a local date from the TOML document, or return a default.- Parameters:
path- The key path.defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
TomlInvalidTypeException- If the value is present but not aLocalDate, or any element of the path preceding the final key is not a table.
-
isLocalTime
Check if a value in the TOML document is aLocalTime.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
trueif the value can be obtained as aLocalTime.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
isLocalTime
Check if a value in the TOML document is aLocalTime.- Parameters:
path- The key path.- Returns:
trueif the value can be obtained as aLocalTime.
-
getLocalTime
Get a local time from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not aLocalTime, or any element of the path preceding the final key is not a table.
-
getLocalTime
Get a local time from the TOML document.- Parameters:
path- The key path.- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
TomlInvalidTypeException- If the value is present but not aLocalTime, or any element of the path preceding the final key is not a table.
-
getLocalTime
Get a local time from the TOML document, or return a default.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not aLocalTime, or any element of the path preceding the final key is not a table.
-
getLocalTime
Get a local time from the TOML document, or return a default.- Parameters:
path- The key path.defaultValue- A supplier for the default value.- Returns:
- The value, or the default.
- Throws:
TomlInvalidTypeException- If the value is present but not aLocalTime, or any element of the path preceding the final key is not a table.
-
isArray
Check if a value in the TOML document is an array.- Parameters:
dottedKey- A dotted key (e.g."server.addresses").- Returns:
trueif the value can be obtained as an array.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
isArray
Check if a value in the TOML document is an array.- Parameters:
path- The key path.- Returns:
trueif the value can be obtained as an array.
-
getArray
Get an array from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.addresses").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not an array, or any element of the path preceding the final key is not a table.
-
getArray
Get an array from the TOML document.- Parameters:
path- The key path.- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
TomlInvalidTypeException- If the value is present but not an array, or any element of the path preceding the final key is not a table.
-
getArrayOrEmpty
Get an array from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.addresses").- Returns:
- The value, or an empty array if no array was set in the TOML document.
- Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not an array, or any element of the path preceding the final key is not a table.
-
getArrayOrEmpty
Get an array from the TOML document.- Parameters:
path- The key path.- Returns:
- The value, or an empty array if no array was set in the TOML document.
- Throws:
TomlInvalidTypeException- If the value is present but not an array, or any element of the path preceding the final key is not a table.
-
isTable
Check if a value in the TOML document is a table.- Parameters:
dottedKey- A dotted key (e.g."server.address").- Returns:
trueif the value can be obtained as a table.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
isTable
Check if a value in the TOML document is a table.- Parameters:
path- The key path.- Returns:
trueif the value can be obtained as a table.
-
getTable
Get a table from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.address").- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not a table, or any element of the path preceding the final key is not a table.
-
getTable
Get a table from the TOML document.- Parameters:
path- The key path.- Returns:
- The value, or
nullif no value was set in the TOML document. - Throws:
TomlInvalidTypeException- If the value is present but not a table, or any element of the path preceding the final key is not a table.
-
getTableOrEmpty
Get a table from the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The value, or an empty table if no value was set in the TOML document.
- Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If the value is present but not a table, or any element of the path preceding the final key is not a table.
-
getTableOrEmpty
Get a table from the TOML document.- Parameters:
path- The key path.- Returns:
- The value, or an empty table if no value was set in the TOML document.
- Throws:
TomlInvalidTypeException- If the value is present but not a table, or any element of the path preceding the final key is not a table.
-
inputPositionOf
Get the position where a key is defined in the TOML document.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The input position, or
nullif the key was not set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If any element of the path preceding the final key is not a table.
-
inputPositionOf
Get the position where a key is defined in the TOML document.For a non-empty path, this is the position of
entry(List).- Parameters:
path- The key path.- Returns:
- The input position, or
nullif the key was not set in the TOML document. - Throws:
TomlInvalidTypeException- If any element of the path preceding the final key is not a table.
-
comments
Get the comments attached to a key.Returns the comments in document order: the run directly above the key, if any, then the comment on its line, if any, so at most two, each with its
TomlComment.placement().Returns an empty list if the key was not set in the document or has no comments; use
contains(String)to tell those apart.The comments on a
[[x]]header are attached to the table it opens, socomments("x")is empty and they are read withgetArray("x").comments(0)and so on.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The attached comments, in document order. Unmodifiable.
- Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If any element of the path preceding the final key is not a table.
-
comments
Get the comments attached to a key.Returns the comments in document order: the run directly above the key, if any, then the comment on its line, if any, so at most two, each with its
TomlComment.placement().Returns an empty list if the key was not set in the document or has no comments; use
contains(List)to tell those apart.The comments on a
[[x]]header are attached to the table it opens, socomments("x")is empty and they are read withgetArray("x").comments(0)and so on.This is a shortcut for
entry(List), returning its comments.- Parameters:
path- The key path.- Returns:
- The attached comments, in document order. Unmodifiable.
- Throws:
TomlInvalidTypeException- If any element of the path preceding the final key is not a table.
-
comment
Get the comment attached to a key at a placement.Returns
nullif the key was not set in the document or has no comment at that placement; usecontains(String)to tell those apart.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").placement-TomlComment.Placement.ABOVEfor the run directly above the key, orTomlComment.Placement.AFTERfor the comment on its line.- Returns:
- The comment at that placement, or
nullif there is none. - Throws:
NullPointerException- IfdottedKeyorplacementisnull.IllegalArgumentException- If the key cannot be parsed, orplacementisTomlComment.Placement.UNATTACHED.TomlInvalidTypeException- If any element of the path preceding the final key is not a table.
-
comment
Get the comment attached to a key at a placement.Returns
nullif the key was not set in the document or has no comment at that placement; usecontains(List)to tell those apart.This is a shortcut for
entry(List), returningTomlEntry.comment(TomlComment.Placement).- Parameters:
path- The key path.placement-TomlComment.Placement.ABOVEfor the run directly above the key, orTomlComment.Placement.AFTERfor the comment on its line.- Returns:
- The comment at that placement, or
nullif there is none. - Throws:
NullPointerException- Ifplacementisnull.IllegalArgumentException- IfplacementisTomlComment.Placement.UNATTACHED.TomlInvalidTypeException- If any element of the path preceding the final key is not a table.
-
entry
Get the entry for a key.The key is parsed using TOML key syntax, so keys containing characters other than
A-Z,a-z,0-9,_and-must be quoted (e.g."\"@key\""). To look up a raw key name without quoting, such as one returned bykeySet(), useentry(List)instead.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The entry, or
nullif the key was not set in the TOML document. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If any element of the path preceding the final key is not a table.
-
entry
Get the entry for a key.The entry is the
TomlKeyValuethatelements()holds for the key, in the table the path leads to.get(List),inputPositionOf(List)andcomments(List)are shortcuts that read the value, position and comments of this entry. An empty path names this table itself, which is not an entry, so it returnsnull.- Parameters:
path- The key path.- Returns:
- The entry, or
nullif the key was not set in the TOML document. - Throws:
TomlInvalidTypeException- If any element of the path preceding the final key is not a table.
-
elements
List<TomlElement> elements()Get the elements written in this table, in document order.Each element is a
TomlKeyValue, an entry of this table, or an unattachedTomlComment. The entries are thoseentrySet()holds. A comment is unattached when it is neither directly above an entry nor on its line: a run separated by a blank line from the entry below it, a run at the end of a section or of the document, or, in an inline table, a comment on a line with no entry.- Returns:
- The elements, in document order. Unmodifiable.
-
toMap
Get the entries of this table as aMap.Note that this does not do a deep conversion. If this table contains tables or arrays, they will be of type
TomlTableorTomlArrayrespectively.- Returns:
- The entries of this table as a
Map.
-
toJson
Return a representation of this table using JSON.- Parameters:
options- Options for the JSON encoder.- Returns:
- A JSON representation of this table.
-
toJson
Return a representation of this table using JSON.- Parameters:
options- Options for the JSON encoder.- Returns:
- A JSON representation of this table.
-
toJson
Append a JSON representation of this table 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 table 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 table using TOML, written with the default options.A
TomlParseResultis written keeping its layout: the text it was parsed from is written back, with only what the editing API changed written anew; any other table, including a table of a parse result rather than the result itself, is written in the default style, keeping the literal form each of its values was parsed with.- Returns:
- A TOML representation of this table.
- See Also:
-
toToml
Return a representation of this table using TOML.A
TomlParseResultkeeps as much of its existing structure and format asoptionsask for; seeTomlWriteOptions.Keep. Any other table is written in the default style, keeping the literal form of each value unless the options ask forTomlWriteOptions.Keep.NOTHING. SeetoToml().- Parameters:
options- The options to write with.- Returns:
- A TOML representation of this table.
- Throws:
IllegalArgumentException- If the version the options write for cannot write this table: 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 table 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 table 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 table: 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:
-
as
Bind this table to a Java type, with the default options.- Type Parameters:
T- The type to bind to.- Parameters:
type- The type to bind to.- Returns:
- A new instance of the type, holding the values of this table.
- Throws:
TomlBindException- If any value of this table cannot be bound.IllegalArgumentException- If the type, or a type it holds, cannot be bound to.- See Also:
-
as
Bind this table to a Java type.record Server(String host, int port) {} record Config(String name, List<Server> servers) {} Config config = Toml.parse(path).as(Config.class, TomlBindOptions.defaults());The value of each key or element is bound to the type declared for it, as follows:
- A string to
String, an enum constant, orcharfor a string of one character. An enum constant is matched by its name, or else by its name ignoring case and with-and space read as_; a constant with aTomlNameannotation is matched by the annotation's value only. - An integer to
long,int,short,byte,BigInteger, or to a floating point type if it can be represented exactly. A value out of range for the type is an error. - A float to
double,floatorBigDecimal. - A boolean to
boolean. - An offset date-time to
OffsetDateTime,ZonedDateTimeorInstant, and a local date-time, date or time toLocalDateTime,LocalDateorLocalTime. - An array to a
List,Set,Collection,Iterable, a concrete collection class, or a Java array. - A table to a record, a class, or a
MapwithStringkeys. - Any value to
Object, unchanged, and a table or array toTomlTableorTomlArray, or to a copy of it forMutableTomlTableorMutableTomlArray. - Any value to
Optional<T>, by binding it toT. - Any value to a type that has a converter in the options, by that converter.
A table is bound to a record through its canonical constructor, with a key for each component. It is bound to a class by creating an instance with its constructor without parameters, then setting a field for each key. Every field of the class and its superclasses is bound except static, transient and final fields. The key of a field or component is its name, converted by the options' key naming, or the value of its
TomlNameannotation.A key the table does not have is bound as follows:
- An
Optionalis empty. - A field of a class keeps the value it was given when the instance was created.
- A record component, or a field of a class that is
nullonce the instance is created, isnullif it is nullable, and an error if it is nevernull. A primitive is nevernull; otherwise, an annotation namedNonNull,NotNullorNonnullmarks a field or component as nevernull, and one namedNullablemarks it as nullable, from any package, as long as the annotation is kept at runtime. Without either, it is nevernullif its class, an enclosing class, its package or its module is annotated as JSpecify'sNullMarked, and nullable otherwise.
Binding does not stop at the first error. Every value is bound, and the errors, each with the path and position of the value, are thrown together in a
TomlBindException. An exception thrown by a record's constructor or a converter is reported as an error at the position of the value being bound.TomlJ binds to private fields and classes by reflection. In a named module, the package holding them must be opened to the module
org.tomlj.- Type Parameters:
T- The type to bind to.- Parameters:
type- The type to bind to.options- The options to bind with.- Returns:
- A new instance of the type, holding the values of this table.
- Throws:
TomlBindException- If any value of this table cannot be bound.IllegalArgumentException- If the type, or a type it holds, cannot be bound to.
- A string to
-
as
Bind this table to a generic Java type, with the default options.- Type Parameters:
T- The type to bind to.- Parameters:
type- The type to bind to.- Returns:
- A new instance of the type, holding the values of this table.
- Throws:
TomlBindException- If any value of this table cannot be bound.IllegalArgumentException- If the type, or a type it holds, cannot be bound to.- See Also:
-
as
Bind this table to a generic Java type.This binds as
as(Class, TomlBindOptions)does, to a type such asList<Server>that aClasscannot name.- Type Parameters:
T- The type to bind to.- Parameters:
type- The type to bind to.options- The options to bind with.- Returns:
- A new instance of the type, holding the values of this table.
- Throws:
TomlBindException- If any value of this table cannot be bound.IllegalArgumentException- If the type, or a type it holds, cannot be bound to.
-