com.atlassian.confluence.core
Class DefaultListBuilder<T>

java.lang.Object
  extended by com.atlassian.confluence.core.DefaultListBuilder<T>
All Implemented Interfaces:
ListBuilder<T>, java.lang.Iterable<java.util.List<T>>

public class DefaultListBuilder<T>
extends java.lang.Object
implements ListBuilder<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
 int getAvailableSize()
          Gets the total number of elements available to return if the whole list were requested
 java.util.List<T> getPage(int offset, int maxResults)
          Gets a page of results by providing the offset of the first element in the page, and the page size.
 java.util.List<T> getRange(int startIndex, int endIndex)
          Gets a range of results by providing the indexes of the first and last elements you wish to return.
 java.util.Iterator<java.util.List<T>> 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
 

Method Detail

newInstance

public static <T> DefaultListBuilder<T> newInstance(ListBuilderCallback<T> callback)
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

public java.util.List<T> getRange(int startIndex,
                                  int endIndex)
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 interface ListBuilder<T>
Parameters:
startIndex - the zero-based index of the first result you wish returned
endIndex - 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

public java.util.List<T> getPage(int offset,
                                 int maxResults)
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 interface ListBuilder<T>
Parameters:
offset - the zero-based index of the first result you wish returned
maxResults - 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

public java.util.Iterator<java.util.List<T>> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.util.List<T>>

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 interface ListBuilder<T>
Returns:
the total number of list elements available


Copyright © 2003-2014 Atlassian. All Rights Reserved.