From b89e9d088a7e696440b9fbea973fc187eb8598ad Mon Sep 17 00:00:00 2001 From: Yeregorix Date: Sun, 1 Sep 2024 17:36:06 +0200 Subject: [PATCH] Add MetadataContainer#toBuilder --- .../metadata/builtin/MetadataContainer.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/org/spongepowered/plugin/metadata/builtin/MetadataContainer.java b/src/main/java/org/spongepowered/plugin/metadata/builtin/MetadataContainer.java index 1b2b7eb..6896a56 100644 --- a/src/main/java/org/spongepowered/plugin/metadata/builtin/MetadataContainer.java +++ b/src/main/java/org/spongepowered/plugin/metadata/builtin/MetadataContainer.java @@ -115,6 +115,16 @@ public String toString() { .toString(); } + public MetadataContainer.Builder toBuilder() { + final Builder builder = new Builder(); + builder.loader = this.loader; + builder.license = this.license; + builder.mappings = this.mappings; + builder.globalMetadata = this.globalMetadata; + builder.metadata.addAll(this.metadata); + return builder; + } + public static final class Builder { final Set metadata = new LinkedHashSet<>(); @@ -150,6 +160,13 @@ public Builder globalMetadata(final Inheritable globalMetadata) { } public Builder metadata(final List metadata) { + Objects.requireNonNull(metadata, "metadata"); + this.metadata.clear(); + this.metadata.addAll(metadata); + return this; + } + + public Builder addMetadata(final List metadata) { this.metadata.addAll(Objects.requireNonNull(metadata, "metadata")); return this; }