Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

zihuaweng
Copy link

Fixes #1050

Copy link
Collaborator

@nhachicha nhachicha left a 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);
Copy link
Collaborator

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());
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New feature: findLast(int), findFirst(int), findRandom(int)
3 participants