Skip to content

feature(nbt): CompoundBinaryTag#createBuilder #1266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main/4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ public interface CompoundBinaryTag extends BinaryTag, CompoundTagSetter<Compound
return BinaryTagTypes.COMPOUND;
}

/**
* Creates a builder, pre-filled with the contents of this compound.
*
* @return a new builder
* @since 4.24.0
*/
Builder createBuilder();

/**
* Gets a set of all keys.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public boolean contains(final @NotNull String key, final @NotNull BinaryTagType<
return tag != null && type.test(tag.type());
}

@Override
public Builder createBuilder() {
return new CompoundTagBuilder(new HashMap<>(this.tags)); // explicitly copy
}

@Override
public @NotNull Set<String> keySet() {
return Collections.unmodifiableSet(this.tags.keySet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
final class CompoundTagBuilder implements CompoundBinaryTag.Builder {
private @Nullable Map<String, BinaryTag> tags;

CompoundTagBuilder() {
}

CompoundTagBuilder(final Map<String, BinaryTag> tags) {
this.tags = tags;
}

private Map<String, BinaryTag> tags() {
if (this.tags == null) {
this.tags = new HashMap<>();
Expand Down