Skip to content

Commit b5b3c40

Browse files
committed
Document CompoundTag add/set API behaviors
1 parent 598fc18 commit b5b3c40

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎src/main/java/org/glavo/nbt/tag/CompoundTag.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@
3030
///
3131
/// All elements in the compound tag must have a unique name.
3232
///
33+
/// `CompoundTag` supports fluent addition/setting operations. It has two families of APIs for adding/setting subtags:
34+
///
35+
/// - The `add` family of APIs, used to add new subtags.
36+
/// If a subtag with the same name already exists, the old subtag will be removed first.
37+
/// - The `set` family of APIs, used to set the value of a subtag.
38+
/// If no subtag with the same name exists, a new subtag will be created.
39+
///
40+
/// Although both can be used to add subtags, they have different behaviors for existing subtags:
41+
///
42+
/// - The `add` family of APIs will not throw exceptions.
43+
/// When a subtag with the same name exists, it will overwrite the old tag.
44+
/// These methods are more suitable for use when constructing a `CompoundTag`.
45+
/// - The `set` family of APIs will not remove any tags from the current `CompoundTag`.
46+
/// This means that subtags previously obtained through the `get` method will not be invalidated by the `set` method.
47+
/// However, if the type of the subtag does not match the value being set (for example, if there is already a StringTag named `foo`,
48+
/// but you try to call `setInt("foo", ...)`), an `IllegalStateException` will be thrown.
49+
/// These methods are more suitable for modifying existing tags.
50+
///
3351
/// @see Tag
3452
/// @see ParentTag
3553
public final class CompoundTag extends ParentTag<Tag> {

0 commit comments

Comments
 (0)