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 utility class to interact with page sources #4232

Merged
merged 1 commit into from
Feb 27, 2017

Conversation

voievodin
Copy link
Contributor

@voievodin voievodin commented Feb 25, 2017

What does this PR do?

Adds utility methods to interact with pages of elements.

Example:
For the class:

class MyDao {
    Page<MyObject> getObjects(int items, long skip) { 
    // ... 
    }
}

Pages utilities allow to simply iterate through the elements as if there are no pages at all.

MyDao instance = ...

// iterating through pages
for (MyObject obj : Pages.iterate(instance::getObjects)) {
    // ...
}

// iterating through pages with items per page configuration
for (MyObject obj : Pages.iterate(instance::getObjects, 20)) {
    // ...
}

// lazily iterating through pages
for (MyObject obj : Pages.iterateLazily(instance::getObjects)) {
    // ...
}

// lazily iterating through pages with items per page configuration
for (MyObject obj : Pages.iterateLazily(instance::getObjects, 20)) {
    // ...
}

// getting stream of objects
Pages.stream(instance::getObjects)

// getting stream of objects  with items per page configuration
Pages.stream(instance::getObjects, 20)

// getting stream based on lazy iterator
Pages.streamLazily(instance::getObjects)

// getting stream based on lazy iterator with items per page configuration
Pages.streamLazily(instance::getObjects, 20)

Changelog

Added new utility methods for handling pagination of objects.

Release Notes

N/A

Docs PR

N/A

@voievodin voievodin added the kind/enhancement A feature request - must adhere to the feature request template. label Feb 25, 2017
@voievodin voievodin self-assigned this Feb 25, 2017
@codenvy-ci
Copy link

@voievodin voievodin changed the title Add utility class to interruct with page sources Add utility class to interact with page sources Feb 25, 2017
@skabashnyuk skabashnyuk added this to the 5.4.0 milestone Feb 25, 2017
@codenvy-ci
Copy link

@JamesDrummond
Copy link
Contributor

What are "pages" in regards to this utility? Can you provide a use case example?

@voievodin
Copy link
Contributor Author

Page doc.

e.g. code can be changed to

for (Member member : Pages.iterate((max, skip) -> dao.getMembers(orgId, max, skip)) {
    dao.remove(member.getUserId(), member.getOrganizationId());
}

@bmicklea bmicklea removed the request for review from JamesDrummond February 27, 2017 08:28
@voievodin voievodin merged commit 267242c into master Feb 27, 2017
@voievodin voievodin deleted the add_pages_utilities branch February 27, 2017 09:05
@JamesDrummond JamesDrummond mentioned this pull request Mar 8, 2017
9 tasks
JPinkney pushed a commit to JPinkney/che that referenced this pull request Aug 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A feature request - must adhere to the feature request template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants