Skip to content
Merged
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 @@ -244,8 +244,7 @@ public Id withTags(Iterable<Tag> tags) {
/**
* Generate a new id replacing all tags with new ones.
* @param tags The tags to add.
* @return A new id with the only the provided tags. The source id remains
* unchanged.
* @return A new id with only the provided tags. The source id remains unchanged.
* @since 1.1.0
*/
public Id replaceTags(Iterable<Tag> tags) {
Expand Down Expand Up @@ -282,9 +281,15 @@ public String getName() {
* @return A set of dimensions that allows you to break down the name.
*/
public List<Tag> getTags() {
List<Tag> tags = new ArrayList<>();
this.tags.forEach(tags::add);
return Collections.unmodifiableList(tags);
if (this.tags == Tags.empty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to explicitly check for zero length, as it's possible to construct another instance with zero tags, but we don't have that API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth adding API for size/length to Tags. Given this is in the same package, we can make it package private. We could consider separately whether to make it public API if there's good justification for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's possible to construct another instance with zero tags

I'd also note it's not possible with public API, so as long as we don't inadvertently do it, we shouldn't need to worry about that case.

return Collections.emptyList();
}

List<Tag> list = new ArrayList<>(this.tags.size());
for (Tag tag : this.tags) {
list.add(tag);
}
return Collections.unmodifiableList(list);
}

public Iterable<Tag> getTagsAsIterable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ public Tags and(@Nullable Iterable<? extends Tag> tags) {
return merge(Tags.of(tags));
}

/**
* Non-public (for now) method to get the size of this, which can be useful in sizing
* a collection where these elements will be copied.
* @return number of unique {@link Tag} instances in this
*/
int size() {
return length;
}

@Override
public Iterator<Tag> iterator() {
return new ArrayIterator();
Expand Down