realm-kotlin icon indicating copy to clipboard operation
realm-kotlin copied to clipboard

`RealmSet` - basic API

Open edualonso opened this issue 2 years ago • 0 comments

The RealmSet interface is implemented by unmanaged and managed sets. UnmanagedRealmSets implement the interface delegating on mutableSetOf(). ManagedRealmSets are implementing the following:

AbstractMutableSet<E>(), RealmSet<E>

AbstractMutableSet has defaults for quite a lot of operations from the interface which simplifies the implementation of complex operations needed in the Java SDK, e.g. set intersection with retainAll (it is implemented using iterator). These default operations might not be the most efficient as opposed to letting Core do the operation itself, but given that the C-API doesn't expose intersect or union, this seems like the only solution for now.

The trip down to Core is implemented piggybacking on the Converters written for RealmLists.

The test framework is inspired by the one used in RealmListTests with minor changes - it might be worth considering aligning both 🤔

Compiler plugin binding:

  • [x] object helpers for regular realms
  • [x] object helpers for dynamic realms

RealmSet interface - in order to have basic testing roundtrip capabilities we need at least these - observe all the other operations are already implemented by AbstractMutableSet which internally uses iterator():

  • [x] support for unmanaged sets
  • [x] size
  • [x] add
  • [x] clear
  • [x] contains
  • [x] iterator
  • [x] implement Deleteable
  • [x] flows and changesets
  • [x] sync testing
  • [x] documentation
  • [x] changelog entry

Changes to existing features:

  • abstracted operators for collections to become CollectionOperators and piggyback on the existing solution for lists (moved mediator, realmReference and converter to the new interface)
  • abstracted notification changesets to be collection-based and not only list-based
  • reused changesets from core internally without exposing indices as the public Set API doesn't support them but are needed internally to determine which type of changeset to emit
  • unified subscription to add notification callbacks for collections and objects at interop level (not for results)

edualonso avatar Jun 27 '22 21:06 edualonso