FreeBuilder icon indicating copy to clipboard operation
FreeBuilder copied to clipboard

Support SortedMap properties

Open alicederyn opened this issue 10 years ago • 3 comments

The issue that has blocked this is setting the comparator; TreeMap's comparator is immutable, but we want to return an unmodifiable view from getMySortedMapProperty(). Options:

  1. Provide a custom SortedMap implementation in freebuilder.jar with a mutable comparator.
    Disadvantage: we don't currently expect users to ship freebuilder.jar.
  2. Write out a SortedMap proxy inner class.
    Disadvantage: lots of code for a rarely-used feature.
  3. Allow the comparator to be set only once, delaying TreeMap construction until then. The setter should probably be protected.
    Disadvantages:
    • users that want a mutable comparator will have to write one from scratch;
    • mergeFrom won't copy the comparator; and
    • no obvious path to migrate to solutions 1/2 in future, as users may rely on the behaviour of mergeFrom.

alicederyn avatar May 04 '15 14:05 alicederyn

It would be great to have this.

To me option 2 sounds the most reasonable. Can you elaborate on how much code "lots" actually is? :)

Thanks!

cookingfox avatar Apr 12 '16 20:04 cookingfox

SortedMap defines 20 methods, including some returning views that require more inner classes to be defined, adding dozens more methods.

alicederyn avatar Apr 14 '16 00:04 alicederyn

An update on this issue: We now have SortedSet support, using option 3 above (comparator must be set before any other operation is called). Unfortunately it still requires a SortedSet proxy inner class to implement the mutate method; SortedMap will too.

alicederyn avatar Jul 22 '17 21:07 alicederyn