Uploaded image for project: 'Realm Kotlin'
  1. Realm Kotlin
  2. RKOTLIN-343

Add support for RealmSet

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Local
    • ?
    • 5
    • 538
    • Not Needed
    • Kotlin Beta sprint 16, Kotlin Beta sprint 17, Kotlin Beta sprint 30, Kotlin Beta sprint 31, Kotlin Beta sprint 32, Kotlin Beta sprint 33, Kotlin Beta sprint 34

      Follow the pattern of managed/unmanaged used for lists by using delegates.

      An oversimplified API would look like this:

      interface RealmSet<E> : MutableSet<E>
      
      internal class UnmanagedRealmSet<E>: RealmSet<E>,
          MutableSet<E> by mutableSetOf()
      
      internal class ManagedRealmSet<E>(
          val nativePointer: NativePointer
      ): AbstractMutableSet<E>(), RealmSet<E> {
          // TODO
      }
      
      /**
       * Instantiates an **unmanaged** [RealmSet].
       */
      fun <E> realmSetOf(vararg elements: E): RealmSet<E> = UnmanagedRealmSet()
      
      /**
       * Instantiates an **unmanaged** [RealmSet] containing all the entries of this set.
       */
      fun <E> Set<E>.toRealmSet(): RealmSet<E> = TODO()
      

      Observations:

      • the C-API has defined the methods for sets but is still missing their implementations.
      • the majority of methods from the MutableSet interface are already provided by AbstractMutableSet though they might not be optimised, e.g. addAll iterates over all values in the provided collection and then calls add.
      • It doesn't seem necessary to rely on Mixed as the transport solution since the C-API accepts realm_value_t structs, just as RealmList does.

            Assignee:
            eduardo.lopezgutierrez@mongodb.com Eduardo López Gutiérrez (Inactive)
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: