diff --git a/micrometer-core/src/main/java/io/micrometer/core/instrument/Tags.java b/micrometer-core/src/main/java/io/micrometer/core/instrument/Tags.java index 4a79706b83..868c6377f0 100644 --- a/micrometer-core/src/main/java/io/micrometer/core/instrument/Tags.java +++ b/micrometer-core/src/main/java/io/micrometer/core/instrument/Tags.java @@ -36,10 +36,23 @@ public final class Tags implements Iterable { private static final Tags EMPTY = new Tags(new Tag[] {}, 0); + /** + * A private array of {@code Tag} objects containing the sorted and deduplicated tags. + */ private final Tag[] sortedSet; + /** + * The number of valid tags present in the {@link #sortedSet} array. + */ private final int length; + /** + * A private constructor that initializes a {@code Tags} object with a sorted set of + * tags and its length. + * + * @param sortedSet an ordered set of unique tags by key + * @param length the number of valid tags in the {@code sortedSet} + */ private Tags(Tag[] sortedSet, int length) { assert isSortedSet(sortedSet, length) : "bug on caller side: construction invariant violated"; this.sortedSet = sortedSet; @@ -59,6 +72,12 @@ private static boolean isSortedSet(Tag[] sortedSet, int length) { return true; } + /** + * Constructs a {@code Tags} collection from the provided array of tags. + * + * @param tags an array of {@code Tag} objects, possibly unordered and/or containing duplicates. + * @return a {@code Tags} instance with a deduplicated and ordered set of tags. + */ private static Tags make(Tag[] tags) { int len = tags.length; if (!isSortedSet(tags, len)) { @@ -68,6 +87,12 @@ private static Tags make(Tag[] tags) { return new Tags(tags, len); } + /** + * Removes duplicate tags from an ordered array of tags. + * + * @param tags an ordered array of {@code Tag} objects. + * @return the number of unique tags in the {@code tags} array after removing duplicates. + */ private static int dedup(Tag[] tags) { int n = tags.length; @@ -86,6 +111,13 @@ private static int dedup(Tag[] tags) { return j; } + /** + * Constructs a {@code Tags} instance by merging two sets of tags in time + * proportional to the sum of their sizes. + * + * @param other the set of tags to merge with this one. + * @return a {@code Tags} instance with the merged sets of tags. + */ private Tags merged(Tags other) { if (other.length == 0) { return this;