immutables / immutables

Annotation processor to create immutable objects and builders. Feels like Guava's immutable collections but for regular value objects. JSON, Jackson, Gson, JAX-RS integrations included

Home Page:http://immutables.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consider adding support for Guava `ImmutableSortedSet`

bhamiltoncx opened this issue · comments

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.)

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

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

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

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

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!