Skip to content
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

Refactor ImmutableLinkedHashSet #513

Merged
merged 1 commit into from
Feb 23, 2022
Merged

Conversation

brfrn169
Copy link
Collaborator

This PR changes ImmutableLinkedHashSet to use ImmutableSet internally and delegate to it. Please take a look!

@brfrn169 brfrn169 self-assigned this Feb 18, 2022
Copy link
Contributor

@thongdk8 thongdk8 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!
But, I left one question.

immutable = true;
public ImmutableLinkedHashSet(Collection<? extends E> data) {
super(0);
this.data = ImmutableSet.copyOf(data);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering. Is it guaranteed to keep the insertion order even if it's copied (not actually copied behind the scene, though) to ImmutableSet?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, ImmutableSet guarantees to keep the insertion order. Actually, I didn't know that before working on this change, but it does according to the following document:
https://guava.dev/releases/30.1-jre/api/docs/com/google/common/collect/ImmutableCollection.html

Deterministic iteration. The iteration order is always well-defined, depending on how the collection was created. Typically this is insertion order unless an explicit ordering is otherwise specified (e.g. ImmutableSortedSet.naturalOrder()).

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, cool. Thank you!

@brfrn169 brfrn169 merged commit d68f4c3 into master Feb 23, 2022
@brfrn169 brfrn169 deleted the refactor-ImmutableLinkedHashSet branch February 23, 2022 07:30
brfrn169 added a commit that referenced this pull request Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants