Created
April 14, 2017 17:21
-
-
Save vonox7/da55db1dce8e84a7abe9e806e285c579 to your computer and use it in GitHub Desktop.
Realm Sort Bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.moshbit.realmsortbug | |
| import android.app.Activity | |
| import android.content.Context | |
| import android.os.Bundle | |
| import io.realm.Realm | |
| import io.realm.RealmConfiguration | |
| import io.realm.RealmObject | |
| import io.realm.Sort | |
| class MainActivity : Activity() { | |
| val names = """cbaCBA123,.-!+'?<>;:_#*=()/&%$ "zxyZXY""".toCharArray() | |
| fun init(context: Context) { | |
| // Init realm | |
| Realm.init(context) | |
| // Init configuration | |
| val configuration = RealmConfiguration.Builder() | |
| .name("app.realm") | |
| .modules(Realm.getDefaultModule()) | |
| // Create config | |
| val config = configuration.build() | |
| // Apply config as default | |
| Realm.setDefaultConfiguration(config) | |
| } | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_main) | |
| init(this) | |
| val realm = Realm.getDefaultInstance() | |
| realm.executeTransaction { tx -> | |
| tx.deleteAll() | |
| names.forEach { name -> | |
| tx.insert(Dog().apply { this.name = "$name" }) | |
| } | |
| } | |
| println("--------------------------------------") | |
| println("jvm unsorted: " + names.joinToString(separator = "")) | |
| println("realm unsorted: " + realm.where(Dog::class.java).findAll().joinToString(separator = "", transform = Dog::name)) | |
| println("--------------") | |
| println("jvm sorted: " + names.sorted().joinToString(separator = "")) | |
| println("realm sorted: " + realm.where(Dog::class.java).findAllSorted("name", Sort.ASCENDING).joinToString(separator = "", transform = Dog::name)) | |
| println("--------------------------------------") | |
| } | |
| } | |
| open class Dog : RealmObject() { | |
| open var name: String = "" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: