Interface MutableTomlEntry
- All Superinterfaces:
TomlElement,TomlEntry
- All Known Subinterfaces:
MutableTomlKeyValue
TomlEntry whose value and attached comments can be edited in place.
An entry is obtained from the table or array it belongs to, with MutableTomlTable.entry(java.lang.String) or
MutableTomlArray.entry(int). MutableTomlTable and MutableTomlArray also offer a shortcut for each
comment setter and remover here, taking the key or index of the entry to change.
Not safe for use from multiple threads without external synchronization.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether this entry was changed through the editing API.removeComment(TomlComment.Placement placement) Remove the attached comment at a placement.Remove the run of comment lines written above this entry.Remove the comment written on this entry's line.setComment(String text, TomlComment.Placement placement) Set an attached comment from its text, replacing any comment already atplacement.setComment(TomlComment comment) Set an attached comment, replacing any comment already at its placement.default MutableTomlEntrysetCommentAbove(String... lines) Set the run of comment lines written above this entry, replacing any already there.default MutableTomlEntrysetCommentAbove(List<String> lines) Set the run of comment lines written above this entry, replacing any already there, assetComment(String, TomlComment.Placement)does.default MutableTomlEntrysetCommentAfter(String text) Set the comment written on this entry's line, replacing any already there, assetComment(String, TomlComment.Placement)does.Replace the value this entry holds, asMutableTomlTable.set(java.lang.String, java.lang.Object)orMutableTomlArray.set(int, java.lang.Object)would.Methods inherited from interface org.tomlj.TomlElement
position
-
Method Details
-
setValue
Replace the value this entry holds, asMutableTomlTable.set(java.lang.String, java.lang.Object)orMutableTomlArray.set(int, java.lang.Object)would.Keeps this entry's position, its place in the container's sequence and its attached comments.
- Parameters:
value- The replacement value.- Returns:
- The value this entry held before, as
TomlValue.get()would give it. - Throws:
NullPointerException- Ifvalueisnull.IllegalArgumentException- Ifvaluecannot be converted to a TOML value, or cannot be written as TOML.
-
setCommentAbove
Set the run of comment lines written above this entry, replacing any already there.- Parameters:
lines- The text of each line, asTomlComment.lines()would return it; a line holding a newline is split there.- Returns:
- This entry.
- Throws:
NullPointerException- If a line isnull.IllegalArgumentException- Iflinesis empty, or a line cannot be written as a TOML comment.
-
setCommentAbove
Set the run of comment lines written above this entry, replacing any already there, assetComment(String, TomlComment.Placement)does.The lines are joined with
'\n', so a'\n'within a line starts a new line, as it does insetComment(String, TomlComment.Placement).- Parameters:
lines- The text of each line, asTomlComment.lines()would return it.- Returns:
- This entry.
- Throws:
NullPointerException- Iflines, or a line, isnull.IllegalArgumentException- Iflinesis empty, or a line cannot be written as a TOML comment.
-
setCommentAfter
Set the comment written on this entry's line, replacing any already there, assetComment(String, TomlComment.Placement)does.- Parameters:
text- The comment text, asTomlComment.lines()would return its one line.- Returns:
- This entry.
- Throws:
NullPointerException- Iftextisnull.IllegalArgumentException- Iftextcannot be written as a TOML comment.
-
setComment
Set an attached comment from its text, replacing any comment already atplacement.For
TomlComment.Placement.ABOVE,textis the lines of the run joined with'\n', asTomlComment.text()gives it, so"a\nb"is a run of two lines and""is a run of one empty line; forTomlComment.Placement.AFTER,textis the one line, so a'\n'in it is rejected. A line cannot contain a control character other than tab, or a lone surrogate.- Parameters:
text- The comment's text, asTomlComment.text()would return it.placement- Where the comment sits relative to this entry,TomlComment.Placement.ABOVEorTomlComment.Placement.AFTER.- Returns:
- This entry.
- Throws:
NullPointerException- Iftextorplacementisnull.IllegalArgumentException- IfplacementisTomlComment.Placement.UNATTACHED, or a line cannot be written as a TOML comment.
-
setComment
Set an attached comment, replacing any comment already at its placement.This is how a comment is copied from one entry to another, across documents too: the comment's text is kept, but the copy stored here has no position, regardless of whether
commenthad one.- Parameters:
comment- The comment, withTomlComment.placement()eitherTomlComment.Placement.ABOVEorTomlComment.Placement.AFTER.- Returns:
- This entry.
- Throws:
NullPointerException- Ifcommentisnull.IllegalArgumentException- Ifcommentis unattached.
-
removeCommentAbove
MutableTomlEntry removeCommentAbove()Remove the run of comment lines written above this entry.Removing a comment that is not there changes nothing and is not a modification.
- Returns:
- This entry.
-
removeCommentAfter
MutableTomlEntry removeCommentAfter()Remove the comment written on this entry's line.Removing a comment that is not there changes nothing and is not a modification.
- Returns:
- This entry.
-
removeComment
Remove the attached comment at a placement.Removing a comment that is not there changes nothing and is not a modification.
- Parameters:
placement- Which attached comment to remove,TomlComment.Placement.ABOVEorTomlComment.Placement.AFTER.- Returns:
- This entry.
- Throws:
NullPointerException- Ifplacementisnull.IllegalArgumentException- IfplacementisTomlComment.Placement.UNATTACHED.
-
isModified
boolean isModified()Whether this entry was changed through the editing API.- Returns:
trueif this entry was added, its value replaced, an attached comment set or removed, or the table or array it holds changed.
-