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

Consider adding support for Guava ImmutableSortedSet #53

Closed
bhamiltoncx opened this issue Nov 20, 2014 · 5 comments
Closed

Consider adding support for Guava ImmutableSortedSet #53

bhamiltoncx opened this issue Nov 20, 2014 · 5 comments
Milestone

Comments

@bhamiltoncx
Copy link
Contributor

The current philosophy of Immutables is to intentionally keep the number of supported containers to a minimum, but it also mentions the specific set of containers could change after discussion.

In the Buck project, we depend pretty heavily on ImmutableSortedSet in our immutable data structures which we create from filesystem listings or glob match results. We use ImmutableSortedSet so our objects behave identically regardless of the behavior of the filesystem listing order (which is OS- and filesystem-dependent).

We'd love to move these data structures to the Immutables library, but it means we have to push sorting from creation time to consumption time, which is a bit annoying (especially in tests). It'd be nice if we could do something like:

@Value.Immutable
public interface FilesystemData {
  String globPattern;
  SortedSet<String> matchingFilenames;
}

If it helps, we don't use any custom Comparators; we always use natural ordering today. (I agree it might be a bit tricky to annotate the Comparator to use for a SortedSet.)

@bhamiltoncx
Copy link
Contributor Author

(Whoops, sorry, didn't mean to close.)

@elucash
Copy link
Member

elucash commented Nov 20, 2014

I've thought about that, adding support for natural ordering, you nailed it down - it's a tricky with comparator. How about Sorted/Navigable map in addition?

SortedSet, NavigableSet -> ImmutableSortedSet
SortedMap, NavigableMap -> ImmutableSortedMap

@Coneko
Copy link

Coneko commented Nov 20, 2014

Sounds great! That's exactly what we would use.

@bhamiltoncx
Copy link
Contributor Author

Yes, that would be perfect. I would be fine starting out with no support for custom Comparators, that can come later.

@elucash elucash added this to the 1.1 milestone Nov 22, 2014
elucash added a commit that referenced this issue Dec 16, 2014
elucash added a commit that referenced this issue Dec 16, 2014
elucash added a commit that referenced this issue Dec 19, 2014
@elucash
Copy link
Member

elucash commented Dec 21, 2014

SortedSet/NavigableSet/SortedMap/NavigableMap attributes specifying @Value.NaturalOrder or @Value.ReverseOrder annotation.

When using order annotations these collections have special support, if you want to use custom comparator, just remove annotation and build ImmutableSortedSet manually. I do not see how custom comparators could be supported internally in a meaningful way (refer to companion comparator attributes and requiring special sequence of build seems too awkward).
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants