Interface MutableTomlTable
- All Superinterfaces:
TomlTable
- All Known Subinterfaces:
TomlParseResult
TomlTable whose values can be edited in place.
A value set through this interface is any value a TomlTable can hold. An Integer, Short or
Byte is widened to a Long and a Float to a Double; a Map with String
keys becomes a table and a Collection an array, their values converted the same way; a TomlValue
stores what it holds. null throws a NullPointerException and anything else an
IllegalArgumentException.
A key or a String value must not contain an unpaired surrogate, an OffsetDateTime's offset
must be a whole number of minutes, and a LocalDate, LocalDateTime or
OffsetDateTime must have a year between 0 and 9999, since none of these can be written as TOML.
A TomlTable or TomlArray stored as a value is stored as a deep copy, so later changes to the original
are not seen; the stored copy is edited through the getters that return it.
An entry's attached comments are edited through its MutableTomlKeyValue (or MutableTomlEntry)
obtained from entry(java.lang.String), or through the shortcuts here. An unattached comment is added after the last element
with addComment(java.lang.String...) and removed with removeComment(java.lang.String, org.tomlj.TomlComment.Placement); it can also be inserted before or after an entry
with insertCommentBefore(java.lang.String, java.lang.String...) or insertCommentAfter(java.lang.String, java.lang.String...). An entry or a comment can also be inserted before
or after any element of this table's sequence, as TomlTable.elements() returns it, with insertBefore(java.lang.String, java.lang.String, java.lang.Object),
insertAfter(java.lang.String, java.lang.String, java.lang.Object), insertCommentBefore(java.lang.String, java.lang.String...), or insertCommentAfter(java.lang.String, java.lang.String...).
A table is written back out with TomlTable.toToml(), and reformat(TomlWriteOptions.Keep) makes it, and
everything nested in it, keep less of its existing structure and format.
Not safe for use from multiple threads without external synchronization.
-
Method Summary
Modifier and TypeMethodDescriptiondefault MutableTomlTableaddComment(String... lines) Add an unattached comment, after the elements already written, asaddComment(List)does.default MutableTomlTableaddComment(List<String> lines) Add an unattached comment, after the elements already written.addComment(TomlComment comment) Add a comment, after the elements already written.voidclear()Remove every entry from this table.static MutableTomlTableCreate a table from aMap.static MutableTomlTableCreate a deep copy of a table.static MutableTomlTablecreate()Create a new, empty table.static MutableTomlTableCreate a new, empty inline table.default @Nullable MutableTomlKeyValueGet the entry for a key.@Nullable MutableTomlKeyValueGet the entry for a key.default @Nullable MutableTomlArrayGet an array from the TOML document.default @Nullable MutableTomlArrayGet an array from the TOML document.default MutableTomlArraygetOrCreateArray(String dottedKey) Get the array at a key, creating it, and any intermediate table that does not already exist, if necessary.getOrCreateArray(List<String> path) Get the array at a path, creating it, and any intermediate table that does not already exist, if necessary.default MutableTomlTablegetOrCreateTable(String dottedKey) Get the table at a key, creating it, and any intermediate table that does not already exist, if necessary.getOrCreateTable(List<String> path) Get the table at a path, creating it, and any intermediate table that does not already exist, if necessary.default @Nullable MutableTomlTableGet a table from the TOML document.default @Nullable MutableTomlTableGet a table from the TOML document.default MutableTomlTableinsertAfter(String anchorDottedKey, String key, Object value) Insert a value into this table after an existing entry, asinsertAfter(List, String, Object)does.insertAfter(List<String> anchorPath, String key, Object value) Insert a value into this table after an existing entry.insertAfter(TomlElement anchor, String key, Object value) Insert a value into this table immediately after an element of its sequence.default MutableTomlTableinsertBefore(String anchorDottedKey, String key, Object value) Insert a value into this table before an existing entry, asinsertBefore(List, String, Object)does.insertBefore(List<String> anchorPath, String key, Object value) Insert a value into this table before an existing entry.insertBefore(TomlElement anchor, String key, Object value) Insert a value into this table immediately before an element of its sequence.default MutableTomlTableinsertCommentAfter(String anchorDottedKey, String... lines) Insert an unattached comment into this table after an existing entry, asinsertCommentAfter(List, List)does.default MutableTomlTableinsertCommentAfter(String anchorDottedKey, List<String> lines) Insert an unattached comment into this table after an existing entry, asinsertCommentAfter(List, List)does.default MutableTomlTableinsertCommentAfter(String anchorDottedKey, TomlComment comment) Insert a comment into this table after an existing entry, asinsertCommentAfter(List, TomlComment)does.default MutableTomlTableinsertCommentAfter(List<String> anchorPath, String... lines) Insert an unattached comment into this table after an existing entry, asinsertCommentAfter(List, List)does.default MutableTomlTableinsertCommentAfter(List<String> anchorPath, List<String> lines) Insert an unattached comment into this table after an existing entry, asinsertCommentAfter(List, TomlComment)places one.insertCommentAfter(List<String> anchorPath, TomlComment comment) Insert a comment into this table after an existing entry.default MutableTomlTableinsertCommentAfter(TomlElement anchor, String... lines) Insert an unattached comment into this table immediately after an element of its sequence, asinsertCommentAfter(TomlElement, List)does.default MutableTomlTableinsertCommentAfter(TomlElement anchor, List<String> lines) Insert an unattached comment into this table immediately after an element of its sequence, asinsertCommentAfter(TomlElement, TomlComment)places one.insertCommentAfter(TomlElement anchor, TomlComment comment) Insert a comment into this table immediately after an element of its sequence.default MutableTomlTableinsertCommentBefore(String anchorDottedKey, String... lines) Insert an unattached comment into this table before an existing entry, asinsertCommentBefore(List, List)does.default MutableTomlTableinsertCommentBefore(String anchorDottedKey, List<String> lines) Insert an unattached comment into this table before an existing entry, asinsertCommentBefore(List, List)does.default MutableTomlTableinsertCommentBefore(String anchorDottedKey, TomlComment comment) Insert a comment into this table before an existing entry, asinsertCommentBefore(List, TomlComment)does.default MutableTomlTableinsertCommentBefore(List<String> anchorPath, String... lines) Insert an unattached comment into this table before an existing entry, asinsertCommentBefore(List, List)does.default MutableTomlTableinsertCommentBefore(List<String> anchorPath, List<String> lines) Insert an unattached comment into this table before an existing entry, asinsertCommentBefore(List, TomlComment)places one.insertCommentBefore(List<String> anchorPath, TomlComment comment) Insert a comment into this table before an existing entry.default MutableTomlTableinsertCommentBefore(TomlElement anchor, String... lines) Insert an unattached comment into this table immediately before an element of its sequence, asinsertCommentBefore(TomlElement, List)does.default MutableTomlTableinsertCommentBefore(TomlElement anchor, List<String> lines) Insert an unattached comment into this table immediately before an element of its sequence, asinsertCommentBefore(TomlElement, TomlComment)places one.insertCommentBefore(TomlElement anchor, TomlComment comment) Insert a comment into this table immediately before an element of its sequence.booleanWhether this table was changed through this interface.default booleanisModified(String dottedKey) Whether an entry of this table was changed through this interface, asisModified(List)reports.booleanisModified(List<String> path) Whether an entry of this table was changed through this interface.Keep less of the existing structure and format of this table, and of everything in it.default @Nullable ObjectRemove a value from this table, asremove(List)does.@Nullable ObjectRemove a value from this table.default MutableTomlTableremoveComment(String dottedKey, TomlComment.Placement placement) Remove the attached comment at a placement, asMutableTomlEntry.removeComment(TomlComment.Placement)does.default MutableTomlTableremoveComment(List<String> path, TomlComment.Placement placement) Remove the attached comment at a placement, asMutableTomlEntry.removeComment(TomlComment.Placement)does.booleanremoveComment(TomlComment comment) Remove an unattached comment, by identity.default MutableTomlTableremoveCommentAbove(String dottedKey) Remove the run of comment lines written above an entry, asMutableTomlEntry.removeCommentAbove()does.default MutableTomlTableremoveCommentAbove(List<String> path) Remove the run of comment lines written above an entry, asMutableTomlEntry.removeCommentAbove()does.default MutableTomlTableremoveCommentAfter(String dottedKey) Remove the comment written on an entry's line, asMutableTomlEntry.removeCommentAfter()does.default MutableTomlTableremoveCommentAfter(List<String> path) Remove the comment written on an entry's line, asMutableTomlEntry.removeCommentAfter()does.default MutableTomlTableSet a value in this table, replacing any value already there, asset(List, Object)does.Set a value in this table, replacing any value already there.default MutableTomlTablesetComment(String dottedKey, String text, TomlComment.Placement placement) Set an attached comment on an entry from its text, asMutableTomlEntry.setComment(String, TomlComment.Placement)does.default MutableTomlTablesetComment(String dottedKey, TomlComment comment) Set an attached comment on an entry, asMutableTomlEntry.setComment(TomlComment)does.default MutableTomlTablesetComment(List<String> path, String text, TomlComment.Placement placement) Set an attached comment on an entry from its text, asMutableTomlEntry.setComment(String, TomlComment.Placement)does.default MutableTomlTablesetComment(List<String> path, TomlComment comment) Set an attached comment on an entry, asMutableTomlEntry.setComment(TomlComment)does.default MutableTomlTablesetCommentAbove(String dottedKey, String... lines) Set the run of comment lines written above an entry, asMutableTomlEntry.setCommentAbove(String...)does.default MutableTomlTablesetCommentAbove(String dottedKey, List<String> lines) Set the run of comment lines written above an entry, asMutableTomlEntry.setCommentAbove(List)does.default MutableTomlTablesetCommentAbove(List<String> path, String... lines) Set the run of comment lines written above an entry, asMutableTomlEntry.setCommentAbove(String...)does.default MutableTomlTablesetCommentAbove(List<String> path, List<String> lines) Set the run of comment lines written above an entry, asMutableTomlEntry.setCommentAbove(List)does.default MutableTomlTablesetCommentAfter(String dottedKey, String text) Set the comment written on an entry's line, asMutableTomlEntry.setCommentAfter(String)does.default MutableTomlTablesetCommentAfter(List<String> path, String text) Set the comment written on an entry's line, asMutableTomlEntry.setCommentAfter(String)does.Methods inherited from interface org.tomlj.TomlTable
comment, comment, comments, comments, contains, contains, dottedEntrySet, dottedEntrySet, dottedKeySet, dottedKeySet, elements, entryPathSet, entryPathSet, entrySet, get, get, getArrayOrEmpty, getArrayOrEmpty, getBoolean, getBoolean, getBoolean, getBoolean, getDouble, getDouble, getDouble, getDouble, getLocalDate, getLocalDate, getLocalDate, getLocalDate, getLocalDateTime, getLocalDateTime, getLocalDateTime, getLocalDateTime, getLocalTime, getLocalTime, getLocalTime, getLocalTime, getLong, getLong, getLong, getLong, getOffsetDateTime, getOffsetDateTime, getOffsetDateTime, getOffsetDateTime, getString, getString, getString, getString, getTableOrEmpty, getTableOrEmpty, inputPositionOf, inputPositionOf, isArray, isArray, isBoolean, isBoolean, isDouble, isDouble, isEmpty, isLocalDate, isLocalDate, isLocalDateTime, isLocalDateTime, isLocalTime, isLocalTime, isLong, isLong, isOffsetDateTime, isOffsetDateTime, isString, isString, isTable, isTable, keyPathSet, keyPathSet, keySet, size, toJson, toJson, toJson, toJson, toMap, toToml, toToml, toToml, toToml
-
Method Details
-
create
Create a new, empty table.- Returns:
- A new, empty table.
-
createInline
Create a new, empty inline table.The table is written with braces on the line of the entry holding it, as
t = { a = 1 }, rather than under a[t]header, unless the document is written keeping nothing (TomlWriteOptions.Keep.NOTHING). A table made withcreate()is written in whichever form the default style chooses for it.- Returns:
- A new, empty inline table.
-
getOrCreateTable
Get the table at a key, creating it, and any intermediate table that does not already exist, if necessary.- Parameters:
dottedKey- A dotted key (e.g."server.address").- Returns:
- The table.
- Throws:
IllegalArgumentException- If the key cannot be parsed, or contains an unpaired surrogate.TomlInvalidTypeException- If an element of the path exists and is not a table.
-
getOrCreateTable
Get the table at a path, creating it, and any intermediate table that does not already exist, if necessary.A table created here is an entry with no position and no comments.
- Parameters:
path- The key path.- Returns:
- The table, or this table if
pathis empty. - Throws:
NullPointerException- If a path element isnull.IllegalArgumentException- If a path element contains an unpaired surrogate.TomlInvalidTypeException- If an element of the path exists and is not a table.
-
getOrCreateArray
Get the array at a key, creating it, and any intermediate table that does not already exist, if necessary.- Parameters:
dottedKey- A dotted key (e.g."server.addresses").- Returns:
- The array.
- Throws:
IllegalArgumentException- If the key cannot be parsed, or contains an unpaired surrogate.TomlInvalidTypeException- If the value exists and is not an array, or an element of the path preceding the final key exists and is not a table.
-
getOrCreateArray
Get the array at a path, creating it, and any intermediate table that does not already exist, if necessary.An array or table created here is an entry with no position and no comments.
- Parameters:
path- The key path.- Returns:
- The array.
- Throws:
IllegalArgumentException- Ifpathis empty, or a path element contains an unpaired surrogate.NullPointerException- If a path element isnull.TomlInvalidTypeException- If the value exists and is not an array, or an element of the path preceding the final key exists and is not a table.
-
set
Set a value in this table, replacing any value already there, asset(List, Object)does.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").value- The value to set.- Returns:
- This table.
- Throws:
NullPointerException- IfdottedKeyorvalueisnull.IllegalArgumentException- If the key cannot be parsed or contains an unpaired surrogate, orvaluecannot be converted to a TOML value or cannot be written as TOML.TomlInvalidTypeException- If an element of the path preceding the final key exists and is not a table.
-
set
Set a value in this table, replacing any value already there.Any intermediate table on the path that does not exist is created. Replacing a value keeps the entry: its position, its place in iteration order and its attached comments. Adding one creates an entry with no position and no comments. A table or array is stored as a deep copy, made as
copyOf(TomlTable)makes one, so it has no positions.A rejected call leaves this table as it was:
valueis converted before any intermediate table is created.- Parameters:
path- The key path.value- The value to set.- Returns:
- This table.
- Throws:
IllegalArgumentException- Ifpathis empty, a path element contains an unpaired surrogate, orvaluecannot be converted to a TOML value or cannot be written as TOML.NullPointerException- If a path element, orvalue, isnull.TomlInvalidTypeException- If an element of the path preceding the final key exists and is not a table.
-
insertBefore
Insert a value into this table before an existing entry, asinsertBefore(List, String, Object)does.- Parameters:
anchorDottedKey- A dotted key naming the entry to insert beside (e.g."server.address").key- The key of the new entry, a single literal key, not a dotted key.value- The value to set.- Returns:
- This table.
- Throws:
NullPointerException- IfanchorDottedKey,key, orvalueisnull.IllegalArgumentException- If the anchor key cannot be parsed,keycontains an unpaired surrogate, orvaluecannot be converted to a TOML value or cannot be written as TOML.NoSuchElementException- If the anchor is not set.TomlKeyAlreadySetException- Ifkeyis already set in the anchor's table.TomlInvalidTypeException- If an element of the anchor path preceding the final key exists and is not a table.
-
insertBefore
Insert a value into this table before an existing entry.The anchor is the path of an existing entry; the new entry is placed immediately before it, in the table that holds it.
keyis one literal key in that table, not a dotted key. The new entry has no position and no attached comments, andvalueis converted asset(List, Object)converts one.A rejected call leaves this table as it was:
valueis converted before the anchor path is walked.- Parameters:
anchorPath- The key path of the existing entry to insert beside.key- The key of the new entry.value- The value to set.- Returns:
- This table.
- Throws:
IllegalArgumentException- IfanchorPathis empty,keycontains an unpaired surrogate, orvaluecannot be converted to a TOML value or cannot be written as TOML.NoSuchElementException- If the anchor is not set.TomlKeyAlreadySetException- Ifkeyis already set in the anchor's table.NullPointerException- If an element ofanchorPath,key, orvalueisnull.TomlInvalidTypeException- If an element ofanchorPathpreceding the final key exists and is not a table.
-
insertAfter
Insert a value into this table after an existing entry, asinsertAfter(List, String, Object)does.- Parameters:
anchorDottedKey- A dotted key naming the entry to insert beside (e.g."server.address").key- The key of the new entry, a single literal key, not a dotted key.value- The value to set.- Returns:
- This table.
- Throws:
NullPointerException- IfanchorDottedKey,key, orvalueisnull.IllegalArgumentException- If the anchor key cannot be parsed,keycontains an unpaired surrogate, orvaluecannot be converted to a TOML value or cannot be written as TOML.NoSuchElementException- If the anchor is not set.TomlKeyAlreadySetException- Ifkeyis already set in the anchor's table.TomlInvalidTypeException- If an element of the anchor path preceding the final key exists and is not a table.
-
insertAfter
Insert a value into this table after an existing entry.The anchor is the path of an existing entry; the new entry is placed immediately after it, in the table that holds it.
keyis one literal key in that table, not a dotted key. The new entry has no position and no attached comments, andvalueis converted asset(List, Object)converts one.A rejected call leaves this table as it was:
valueis converted before the anchor path is walked.- Parameters:
anchorPath- The key path of the existing entry to insert beside.key- The key of the new entry.value- The value to set.- Returns:
- This table.
- Throws:
IllegalArgumentException- IfanchorPathis empty,keycontains an unpaired surrogate, orvaluecannot be converted to a TOML value or cannot be written as TOML.NoSuchElementException- If the anchor is not set.TomlKeyAlreadySetException- Ifkeyis already set in the anchor's table.NullPointerException- If an element ofanchorPath,key, orvalueisnull.TomlInvalidTypeException- If an element ofanchorPathpreceding the final key exists and is not a table.
-
insertBefore
Insert a value into this table immediately before an element of its sequence.The anchor is an element of this table's own
TomlTable.elements(), matched by identity: an element of a sub-table, a copy, or another document is rejected, even if it is equal. It may be an entry or an unattached comment; "before an entry" means before the entry itself, so a comment attached above it stays attached to it. The new entry has no position and no attached comments, andvalueis converted asset(List, Object)converts one.A rejected call leaves this table as it was:
valueis converted beforeanchoris checked.- Parameters:
anchor- The element to insert before.key- The key of the new entry.value- The value to set.- Returns:
- This table.
- Throws:
NullPointerException- Ifanchor,key, orvalueisnull.IllegalArgumentException- Ifkeycontains an unpaired surrogate, orvaluecannot be converted to a TOML value or cannot be written as TOML.NoSuchElementException- Ifanchoris not an element of this table'sTomlTable.elements().TomlKeyAlreadySetException- Ifkeyis already set in this table.
-
insertAfter
Insert a value into this table immediately after an element of its sequence.The new entry is placed immediately after
anchor, matched asinsertBefore(TomlElement, String, Object)matches one. The new entry has no position and no attached comments, andvalueis converted asset(List, Object)converts one.A rejected call leaves this table as it was:
valueis converted beforeanchoris checked.- Parameters:
anchor- The element to insert after.key- The key of the new entry.value- The value to set.- Returns:
- This table.
- Throws:
NullPointerException- Ifanchor,key, orvalueisnull.IllegalArgumentException- Ifkeycontains an unpaired surrogate, orvaluecannot be converted to a TOML value or cannot be written as TOML.NoSuchElementException- Ifanchoris not an element of this table'sTomlTable.elements().TomlKeyAlreadySetException- Ifkeyis already set in this table.
-
remove
Remove a value from this table, asremove(List)does.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- The value that was removed, or
nullif the key was not set. - Throws:
IllegalArgumentException- If the key cannot be parsed.TomlInvalidTypeException- If an element of the path preceding the final key exists and is not a table.
-
remove
Remove a value from this table.The entry is removed, with the comments attached to it. The unattached comments among this table's elements stay where they are.
- Parameters:
path- The key path.- Returns:
- The value that was removed, or
nullif the key was not set, or if an element of the path preceding the final key is missing. - Throws:
IllegalArgumentException- Ifpathis empty.NullPointerException- If a path element isnull.TomlInvalidTypeException- If an element of the path preceding the final key exists and is not a table.
-
clear
void clear()Remove every entry from this table.The unattached comments among this table's elements stay where they are. Clearing a table that is already empty is not a modification.
-
isModified
boolean isModified()Whether this table was changed through this interface.A change is an entry added, replaced or removed, in this table or in any table or array nested within it. A table read from a document, or newly created, reports
false; nothing resets this once it istrue.- Returns:
trueif this table was changed through this interface.
-
isModified
Whether an entry of this table was changed through this interface, asisModified(List)reports.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
trueif the entry was changed;falseif the key is not set.- Throws:
IllegalArgumentException- If the key cannot be parsed.
-
isModified
Whether an entry of this table was changed through this interface.A change is the entry added or replaced, or a change within the table or array it holds.
- Parameters:
path- The key path.- Returns:
trueif the entry was changed;falseif the key is not set. Equivalent toisModified()ifpathis empty.
-
setCommentAbove
Set the run of comment lines written above an entry, asMutableTomlEntry.setCommentAbove(String...)does.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- IfdottedKey, or a line, isnull.IllegalArgumentException- If the key cannot be parsed,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
setCommentAbove
Set the run of comment lines written above an entry, asMutableTomlEntry.setCommentAbove(List)does.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- IfdottedKey,lines, or a line isnull.IllegalArgumentException- If the key cannot be parsed,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
setCommentAbove
Set the run of comment lines written above an entry, asMutableTomlEntry.setCommentAbove(String...)does.- Parameters:
path- The key path.lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- If a path element, or a line, isnull.IllegalArgumentException- Ifpathis empty,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
setCommentAbove
Set the run of comment lines written above an entry, asMutableTomlEntry.setCommentAbove(List)does.- Parameters:
path- The key path.lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- If a path element, or a line, isnull.IllegalArgumentException- Ifpathis empty,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
setCommentAfter
Set the comment written on an entry's line, asMutableTomlEntry.setCommentAfter(String)does.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").text- The comment text, asTomlComment.lines()would return its one line.- Returns:
- This table.
- Throws:
NullPointerException- IfdottedKey, ortext, isnull.IllegalArgumentException- If the key cannot be parsed, ortextcannot be written as a TOML comment.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
setCommentAfter
Set the comment written on an entry's line, asMutableTomlEntry.setCommentAfter(String)does.- Parameters:
path- The key path.text- The comment text, asTomlComment.lines()would return its one line.- Returns:
- This table.
- Throws:
NullPointerException- If a path element, ortext, isnull.IllegalArgumentException- Ifpathis empty, ortextcannot be written as a TOML comment.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
setComment
Set an attached comment on an entry from its text, asMutableTomlEntry.setComment(String, TomlComment.Placement)does.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").text- The comment's text, asTomlComment.text()would return it.placement- Where the comment sits relative to the entry,TomlComment.Placement.ABOVEorTomlComment.Placement.AFTER.- Returns:
- This table.
- Throws:
NullPointerException- IfdottedKey,text, orplacementisnull.IllegalArgumentException- If the key cannot be parsed,placementisTomlComment.Placement.UNATTACHED, or a line oftextcannot be written as a TOML comment.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
setComment
default MutableTomlTable setComment(List<String> path, String text, TomlComment.Placement placement) Set an attached comment on an entry from its text, asMutableTomlEntry.setComment(String, TomlComment.Placement)does.- Parameters:
path- The key path.text- The comment's text, asTomlComment.text()would return it.placement- Where the comment sits relative to the entry,TomlComment.Placement.ABOVEorTomlComment.Placement.AFTER.- Returns:
- This table.
- Throws:
NullPointerException- If a path element,text, orplacementisnull.IllegalArgumentException- Ifpathis empty,placementisTomlComment.Placement.UNATTACHED, or a line oftextcannot be written as a TOML comment.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
setComment
Set an attached comment on an entry, asMutableTomlEntry.setComment(TomlComment)does.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").comment- The comment, withTomlComment.placement()eitherTomlComment.Placement.ABOVEorTomlComment.Placement.AFTER.- Returns:
- This table.
- Throws:
NullPointerException- IfdottedKey, orcomment, isnull.IllegalArgumentException- If the key cannot be parsed, orcommentis unattached.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
setComment
Set an attached comment on an entry, asMutableTomlEntry.setComment(TomlComment)does.- Parameters:
path- The key path.comment- The comment, withTomlComment.placement()eitherTomlComment.Placement.ABOVEorTomlComment.Placement.AFTER.- Returns:
- This table.
- Throws:
NullPointerException- If a path element, orcomment, isnull.IllegalArgumentException- Ifpathis empty, orcommentis unattached.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
removeCommentAbove
Remove the run of comment lines written above an entry, asMutableTomlEntry.removeCommentAbove()does.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- This table.
- Throws:
NullPointerException- IfdottedKeyisnull.IllegalArgumentException- If the key cannot be parsed.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
removeCommentAbove
Remove the run of comment lines written above an entry, asMutableTomlEntry.removeCommentAbove()does.- Parameters:
path- The key path.- Returns:
- This table.
- Throws:
NullPointerException- If a path element isnull.IllegalArgumentException- Ifpathis empty.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
removeCommentAfter
Remove the comment written on an entry's line, asMutableTomlEntry.removeCommentAfter()does.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").- Returns:
- This table.
- Throws:
NullPointerException- IfdottedKeyisnull.IllegalArgumentException- If the key cannot be parsed.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
removeCommentAfter
Remove the comment written on an entry's line, asMutableTomlEntry.removeCommentAfter()does.- Parameters:
path- The key path.- Returns:
- This table.
- Throws:
NullPointerException- If a path element isnull.IllegalArgumentException- Ifpathis empty.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
removeComment
Remove the attached comment at a placement, asMutableTomlEntry.removeComment(TomlComment.Placement)does.- Parameters:
dottedKey- A dotted key (e.g."server.address.port").placement- Which attached comment to remove,TomlComment.Placement.ABOVEorTomlComment.Placement.AFTER.- Returns:
- This table.
- Throws:
NullPointerException- IfdottedKey, orplacement, isnull.IllegalArgumentException- If the key cannot be parsed, orplacementisTomlComment.Placement.UNATTACHED.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
removeComment
Remove the attached comment at a placement, asMutableTomlEntry.removeComment(TomlComment.Placement)does.- Parameters:
path- The key path.placement- Which attached comment to remove,TomlComment.Placement.ABOVEorTomlComment.Placement.AFTER.- Returns:
- This table.
- Throws:
NullPointerException- If a path element, orplacement, isnull.IllegalArgumentException- Ifpathis empty, orplacementisTomlComment.Placement.UNATTACHED.NoSuchElementException- If the key is not set.TomlInvalidTypeException- If an element of the path preceding the final key is not a table.
-
addComment
Add an unattached comment, after the elements already written, asaddComment(List)does.- Parameters:
lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- If a line isnull.IllegalArgumentException- Iflinesis empty, or a line cannot be written as a TOML comment.
-
addComment
Add an unattached comment, after the elements already written.- Parameters:
lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- Iflines, or a line, isnull.IllegalArgumentException- Iflinesis empty, or a line cannot be written as a TOML comment.
-
addComment
Add a comment, after the elements already written.The comment's position is ignored: the copy stored here has none. This is how an unattached comment is copied from one table or array to another, across documents too.
- Parameters:
comment- The comment to add, with no placement.- Returns:
- This table.
- Throws:
NullPointerException- Ifcommentisnull.IllegalArgumentException- Ifcommentis attached.
-
insertCommentBefore
Insert an unattached comment into this table before an existing entry, asinsertCommentBefore(List, List)does.- Parameters:
anchorDottedKey- A dotted key naming the entry to insert beside (e.g."server.address").lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- IfanchorDottedKey,lines, or a line isnull.IllegalArgumentException- If the anchor key cannot be parsed,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element of the anchor path preceding the final key exists and is not a table.
-
insertCommentBefore
Insert an unattached comment into this table before an existing entry, asinsertCommentBefore(List, List)does.- Parameters:
anchorDottedKey- A dotted key naming the entry to insert beside (e.g."server.address").lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- IfanchorDottedKey,lines, or a line isnull.IllegalArgumentException- If the anchor key cannot be parsed,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element of the anchor path preceding the final key exists and is not a table.
-
insertCommentBefore
Insert an unattached comment into this table before an existing entry, asinsertCommentBefore(List, List)does.- Parameters:
anchorPath- The key path of the existing entry to insert beside.lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- If an element ofanchorPath,lines, or a line isnull.IllegalArgumentException- IfanchorPathis empty,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element ofanchorPathpreceding the final key exists and is not a table.
-
insertCommentBefore
Insert an unattached comment into this table before an existing entry, asinsertCommentBefore(List, TomlComment)places one.- Parameters:
anchorPath- The key path of the existing entry to insert beside.lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- If an element ofanchorPath,lines, or a line isnull.IllegalArgumentException- IfanchorPathis empty,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element ofanchorPathpreceding the final key exists and is not a table.
-
insertCommentBefore
Insert a comment into this table before an existing entry, asinsertCommentBefore(List, TomlComment)does.- Parameters:
anchorDottedKey- A dotted key naming the entry to insert beside (e.g."server.address").comment- The comment to insert, with no placement.- Returns:
- This table.
- Throws:
NullPointerException- IfanchorDottedKey, orcomment, isnull.IllegalArgumentException- If the anchor key cannot be parsed, orcommentis attached.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element of the anchor path preceding the final key exists and is not a table.
-
insertCommentBefore
Insert a comment into this table before an existing entry.The comment is inserted as
addComment(TomlComment)adds one, its position ignored, immediately before the anchor entry. The anchor's ownTomlComment.Placement.ABOVErun stays attached to it, so the new comment is written above that run.- Parameters:
anchorPath- The key path of the existing entry to insert beside.comment- The comment to insert, with no placement.- Returns:
- This table.
- Throws:
NullPointerException- If an element ofanchorPath, orcomment, isnull.IllegalArgumentException- IfanchorPathis empty, orcommentis attached.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element ofanchorPathpreceding the final key exists and is not a table.
-
insertCommentAfter
Insert an unattached comment into this table after an existing entry, asinsertCommentAfter(List, List)does.- Parameters:
anchorDottedKey- A dotted key naming the entry to insert beside (e.g."server.address").lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- IfanchorDottedKey,lines, or a line isnull.IllegalArgumentException- If the anchor key cannot be parsed,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element of the anchor path preceding the final key exists and is not a table.
-
insertCommentAfter
Insert an unattached comment into this table after an existing entry, asinsertCommentAfter(List, List)does.- Parameters:
anchorDottedKey- A dotted key naming the entry to insert beside (e.g."server.address").lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- IfanchorDottedKey,lines, or a line isnull.IllegalArgumentException- If the anchor key cannot be parsed,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element of the anchor path preceding the final key exists and is not a table.
-
insertCommentAfter
Insert an unattached comment into this table after an existing entry, asinsertCommentAfter(List, List)does.- Parameters:
anchorPath- The key path of the existing entry to insert beside.lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- If an element ofanchorPath,lines, or a line isnull.IllegalArgumentException- IfanchorPathis empty,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element ofanchorPathpreceding the final key exists and is not a table.
-
insertCommentAfter
Insert an unattached comment into this table after an existing entry, asinsertCommentAfter(List, TomlComment)places one.- Parameters:
anchorPath- The key path of the existing entry to insert beside.lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- If an element ofanchorPath,lines, or a line isnull.IllegalArgumentException- IfanchorPathis empty,linesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element ofanchorPathpreceding the final key exists and is not a table.
-
insertCommentAfter
Insert a comment into this table after an existing entry, asinsertCommentAfter(List, TomlComment)does.- Parameters:
anchorDottedKey- A dotted key naming the entry to insert beside (e.g."server.address").comment- The comment to insert, with no placement.- Returns:
- This table.
- Throws:
NullPointerException- IfanchorDottedKey, orcomment, isnull.IllegalArgumentException- If the anchor key cannot be parsed, orcommentis attached.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element of the anchor path preceding the final key exists and is not a table.
-
insertCommentAfter
Insert a comment into this table after an existing entry.The comment is inserted as
addComment(TomlComment)adds one, its position ignored, immediately after the anchor entry in this table'sTomlTable.elements().- Parameters:
anchorPath- The key path of the existing entry to insert beside.comment- The comment to insert, with no placement.- Returns:
- This table.
- Throws:
NullPointerException- If an element ofanchorPath, orcomment, isnull.IllegalArgumentException- IfanchorPathis empty, orcommentis attached.NoSuchElementException- If the anchor is not set.TomlInvalidTypeException- If an element ofanchorPathpreceding the final key exists and is not a table.
-
insertCommentBefore
Insert an unattached comment into this table immediately before an element of its sequence, asinsertCommentBefore(TomlElement, List)does.- Parameters:
anchor- The element to insert before.lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- Ifanchor,lines, or a line isnull.IllegalArgumentException- Iflinesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- Ifanchoris not an element of this table'sTomlTable.elements().
-
insertCommentBefore
Insert an unattached comment into this table immediately before an element of its sequence, asinsertCommentBefore(TomlElement, TomlComment)places one.- Parameters:
anchor- The element to insert before.lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- Ifanchor,lines, or a line isnull.IllegalArgumentException- Iflinesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- Ifanchoris not an element of this table'sTomlTable.elements().
-
insertCommentBefore
Insert a comment into this table immediately before an element of its sequence.The comment is inserted as
addComment(TomlComment)adds one, its position ignored. The anchor is an element of this table's ownTomlTable.elements(), matched by identity: an element of a sub-table, a copy, or another document is rejected, even if it is equal. It may be an entry or an unattached comment; "before an entry" means before the entry itself, so its own attached comments stay attached to it.- Parameters:
anchor- The element to insert before.comment- The comment to insert, with no placement.- Returns:
- This table.
- Throws:
NullPointerException- Ifanchororcommentisnull.IllegalArgumentException- Ifcommentis attached.NoSuchElementException- Ifanchoris not an element of this table'sTomlTable.elements().
-
insertCommentAfter
Insert an unattached comment into this table immediately after an element of its sequence, asinsertCommentAfter(TomlElement, List)does.- Parameters:
anchor- The element to insert after.lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- Ifanchor,lines, or a line isnull.IllegalArgumentException- Iflinesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- Ifanchoris not an element of this table'sTomlTable.elements().
-
insertCommentAfter
Insert an unattached comment into this table immediately after an element of its sequence, asinsertCommentAfter(TomlElement, TomlComment)places one.- Parameters:
anchor- The element to insert after.lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This table.
- Throws:
NullPointerException- Ifanchor,lines, or a line isnull.IllegalArgumentException- Iflinesis empty, or a line cannot be written as a TOML comment.NoSuchElementException- Ifanchoris not an element of this table'sTomlTable.elements().
-
insertCommentAfter
Insert a comment into this table immediately after an element of its sequence.The comment is inserted as
addComment(TomlComment)adds one, its position ignored, immediately afteranchor, matched asinsertCommentBefore(TomlElement, TomlComment)matches one.- Parameters:
anchor- The element to insert after.comment- The comment to insert, with no placement.- Returns:
- This table.
- Throws:
NullPointerException- Ifanchororcommentisnull.IllegalArgumentException- Ifcommentis attached.NoSuchElementException- Ifanchoris not an element of this table'sTomlTable.elements().
-
removeComment
Remove an unattached comment, by identity.- Parameters:
comment- The comment to remove.- Returns:
trueifcommentwas among this table'sTomlTable.elements(), and was removed. An attached comment is never among them, so removing one here always returnsfalse.
-
reformat
Keep less of the existing structure and format of this table, and of everything in it.A parse result is written from the text it was parsed from, so a table keeps its layout until it is changed. Reformatting it discards that:
- With
TomlWriteOptions.Keep.LAYOUT, which every table starts with, nothing changes. - With
TomlWriteOptions.Keep.NOTATIONits lines keep their order, comments, literal forms and structure, whether a header, dotted keys or an inline table, and take the layout the options give. - With
TomlWriteOptions.Keep.NOTHINGit is written entirely in the default style, as a table built with the editing API is, in the place its header had.
- Parameters:
keep- How much of the existing structure and format of this table to keep.- Returns:
- This table.
- Throws:
NullPointerException- Ifkeepisnull.
- With
-
copyOf
Create a deep copy of a table.The copy is independent of
table: a nested table or array is copied recursively, and later changes to either are not seen by the other. Every entry of the copy has no input position and reports as modified, since none of it was read from a document; the copy itself reportsisModified()falsewhile it has no entries, likecreate(). The comments attached to each entry, and the unattached comments among the table's elements, are kept.- Parameters:
table- The table to copy.- Returns:
- A new, independent table with the same entries.
- Throws:
IllegalArgumentException- If a key intablecontains an unpaired surrogate, or a value in it cannot be written as TOML.
-
copyOf
Create a table from aMap.Each key of
mapis one literal key, not a dotted key. Each value is converted as any value set through this interface is.- Parameters:
map- The map to copy.- Returns:
- A new table with one entry per entry of
map. - Throws:
NullPointerException- If a value inmapisnull.IllegalArgumentException- If a key inmapcontains an unpaired surrogate, or a value in it cannot be converted to a TOML value or cannot be written as TOML.
-
entry
Description copied from interface:TomlTableGet 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 byTomlTable.keySet(), useTomlTable.entry(List)instead. -
entry
Description copied from interface:TomlTableGet the entry for a key.The entry is the
TomlKeyValuethatTomlTable.elements()holds for the key, in the table the path leads to.TomlTable.get(List),TomlTable.inputPositionOf(List)andTomlTable.comments(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. -
getTable
Description copied from interface:TomlTableGet a table from the TOML document. -
getTable
Description copied from interface:TomlTableGet a table from the TOML document. -
getArray
Description copied from interface:TomlTableGet an array from the TOML document. -
getArray
Description copied from interface:TomlTableGet an array from the TOML document.
-