Package com.atlassian.confluence.core
Class DefaultListBuilder<T>
java.lang.Object
com.atlassian.confluence.core.DefaultListBuilder<T>
- All Implemented Interfaces:
ListBuilder<T>
,Iterable<List<T>>
Skeleton implementation of a list builder that takes care of maintaining the class invariants but
delegates the final building of the list to a callback function.
-
Method Summary
Modifier and TypeMethodDescriptionint
Gets the total number of elements available to return if the whole list were requestedgetPage
(int offset, int maxResults) Gets a page of results by providing the offset of the first element in the page, and the page size.getRange
(int startIndex, int endIndex) Gets a range of results by providing the indexes of the first and last elements you wish to return.iterator()
static <T> DefaultListBuilder<T>
newInstance
(ListBuilderCallback<T> callback) Instantiate a new default ListBuilder from a callback.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
newInstance
Instantiate a new default ListBuilder from a callback. We use a factory method so we can take advantage of type inference.- Parameters:
callback
- the callback from which the builder should retrieve data- Returns:
- the appropriate list builder.
-
getRange
Description copied from interface:ListBuilder
Gets a range of results by providing the indexes of the first and last elements you wish to return. This is an inclusive range. Requesting a range that falls outside the list of available elements will result in a short, or empty list.- Specified by:
getRange
in interfaceListBuilder<T>
- Parameters:
startIndex
- the zero-based index of the first result you wish returnedendIndex
- the zero-based index of the last result you wish returned- Returns:
- the list of available results in that range, or an empty list if no results are within the range
-
getPage
Description copied from interface:ListBuilder
Gets a page of results by providing the offset of the first element in the page, and the page size. Requesting a page that falls outside the list of available elements will result in a short, or empty list.- Specified by:
getPage
in interfaceListBuilder<T>
- Parameters:
offset
- the zero-based index of the first result you wish returnedmaxResults
- the size of the page requested- Returns:
- the list of available results in that range, or an empty list if no results are within the range
-
iterator
-
getAvailableSize
public int getAvailableSize()Description copied from interface:ListBuilder
Gets the total number of elements available to return if the whole list were requested- Specified by:
getAvailableSize
in interfaceListBuilder<T>
- Returns:
- the total number of list elements available
-