Support custom sorting in RealmResult and RealmList
Goal
I want to be able to sort RealmResult or RealmList in a custom way. For example it is impossible to sort in Realm for Android by Location. I know there is a specific issue tracking this, but thinking more generally - there will always be another type or way of sorting you haven't gotten around to implementing.
Expected Results
I can implement my own https://developer.android.com/reference/java/util/Comparator.html or similar, and use it directly in a Realm query.
Actual Results
I have to copy the result to a local list and run my custom sort there, loosing the benefits of change listeners etc.
https://github.com/realm/realm-java/issues/2313
https://github.com/realm/realm-java/issues/2744
Hi @snowpong . Thanks for the suggestion. As @Zhuinden points out this is already being tracked by especially #2313. The biggest problem with a custom sorting Comparator is that the sorting is done in C++ while the Comparator is java code. Calling back into Java to do sorting would probably be extremely expensive. That said we haven't really measured it yet, so it might be acceptable for small results.
In any case, i'll close this as an duplicate and let the discussion continue in #2313
@cmelchior Fair enough. I should have searched better when posting the feature request. I see the issue with crossing the JNI barrier and speed.