Skip to content

Commit

Permalink
Add Pagination pagesCount(), isEmpty() and currentSource() (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
DevNatan authored Apr 23, 2024
1 parent a6fe9c6 commit bd5ae43
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,28 @@ public interface Pagination extends ComponentComposition {
@ApiStatus.Experimental
void forceUpdate();

/**
* Gets the total number of pages.
*
* @return The total number of pages. Always <code>1</code> when {@link #isComputed()} is <code>true</code>.
*/
int pagesCount();

/**
* Checks if there's any source in this pagination.
*
* @return Returns <code>true</code> if the pagination is empty, otherwise <code>true</code>.
*/
boolean isEmpty();

/**
* Returns the list of paginated data loaded for the current page.
*
* @return Paginated data for the current page.
* @param <T> The paginated data type.
*/
<T> List<T> currentSource();

/**
* Gets all elements in a given page index based of the specified source.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ private CompletableFuture<List<?>> loadSourceForTheCurrentPage() {
isLoading = false;
simulateStateUpdate();

if (isLazy())
return Pagination.splitSourceForPage(currentPageIndex(), getPageSize(), getPagesCount(), result);
else return result;
return !isLazy()
? result
: Pagination.splitSourceForPage(currentPageIndex(), getPageSize(), getPagesCount(), result);
});
}

Expand Down Expand Up @@ -538,6 +538,22 @@ public void forceUpdate() {
throw new UnsupportedOperationException();
}

@Override
public int pagesCount() {
return isComputed() ? 1 : getPagesCount();
}

@Override
public boolean isEmpty() {
return currSource.isEmpty();
}

@SuppressWarnings("unchecked")
@Override
public <T> List<T> currentSource() {
return (List<T>) currSource;
}

@NotNull
@Override
public Iterator<Component> iterator() {
Expand Down

0 comments on commit bd5ae43

Please sign in to comment.