public final class TagListBuilder extends Object
The builder tracks whether tags are added in sorted order and passes this information to the underlying TagList implementation to optimize performance. For best performance, add tags in lexicographically sorted order by key.
Example usage:
TagListBuilder builder = TagListBuilder.create();
TagList tags = builder
.add("app", "myapp")
.add("env", "prod")
.add("region", "us-east-1")
.buildAndReset();
The builder can be reused after calling buildAndReset():
TagList tags1 = builder.add("key1", "value1").buildAndReset();
TagList tags2 = builder.add("key2", "value2").buildAndReset();
| Modifier and Type | Method and Description |
|---|---|
TagListBuilder |
add(String key,
String value)
Adds a key-value pair to the builder.
|
TagListBuilder |
add(Tag tag)
Adds a Tag object to the builder.
|
TagListBuilder |
add(TagList tags)
Adds all tags from the provided TagList to this builder.
|
TagList |
buildAndReset()
Builds a TagList from the accumulated tags and resets the builder for reuse.
|
static TagListBuilder |
create()
Creates a new TagListBuilder instance.
|
static TagListBuilder |
create(TagList baseTags)
Creates a new TagListBuilder instance with a set of base tags that will be included
in all TagLists built by this builder.
|
void |
reset()
Resets the builder to its initial empty state, allowing it to be reused.
|
public static TagListBuilder create()
public static TagListBuilder create(TagList baseTags)
buildAndReset() call.baseTags - the base tags to include in all built TagLists, must not be nullpublic TagListBuilder add(TagList tags)
tags - the TagList containing tags to add, must not be nullpublic TagListBuilder add(String key, String value)
For optimal performance, add tags in lexicographically sorted order by key. The builder tracks sort order and passes this information to the underlying TagList implementation to avoid unnecessary sorting operations.
key - the tag key, must not be nullvalue - the tag value, must not be nullpublic TagListBuilder add(Tag tag)
tag - the tag to add, must not be null and must have non-null key and valuepublic void reset()
public TagList buildAndReset()