-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add findFirst(int), findLast(int) and findRandom(int) #6778
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @zihuaweng Thanks for your contribution, as mentioned in the comments above there are issues with your implementation (at least for findLast_limit
and findRandom_limit
), findFirst(limit)
could be added best as an extension method for example.
} | ||
|
||
RealmResults<E> results = findAll(); | ||
Collections.shuffle(results); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shuffle
is not supported by 'RealmResults' or 'OrderedRealmCollectionSnapshot', this will throw a UnsupportedOperationException
at runtime.
} | ||
|
||
RealmResults<E> results = findAll(); | ||
results = results.subList(Math.max(results.size() - limit, 0), results.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
java.util.SubList
cannot be cast to io.realm.RealmResults
, this will throw ClassCastException
at runtime
Fixes #1050