T
- The domain object type stored in this list.public abstract class PaginatedList<T>
extends java.lang.Object
implements java.util.List<T>
Pages of results are fetched lazily from DynamoDB as they are needed. Some
methods, such as size()
and
toArray()
, require fetching the entire result set
eagerly. See the javadoc of individual methods for details on which are lazy.
Modifier and Type | Class and Description |
---|---|
private class |
PaginatedList.PaginatedListIterator |
Modifier and Type | Field and Description |
---|---|
protected java.util.List<T> |
allResults
All currently loaded results for this list.
|
protected boolean |
allResultsLoaded
Tracks if all results have been loaded yet or not
|
protected java.lang.Class<T> |
clazz
The class annotated with DynamoDB tags declaring how to load/store
objects into DynamoDB
|
protected AmazonDynamoDB |
dynamo
The client for working with DynamoDB
|
private static java.lang.String |
ITERATION_ONLY_UNSUPPORTED_OPERATION_MESSAGE |
private boolean |
iterationStarted
Keeps track on whether an iterator of the list has been retrieved.
|
protected DynamoDBMapper |
mapper
Reference to the DynamoDB mapper for marshalling DynamoDB attributes back
into objects
|
protected java.util.List<T> |
nextResults
Lazily loaded next results waiting to be added into allResults
|
private DynamoDBMapperConfig.PaginationLoadingStrategy |
paginationLoadingStrategy
The pagination loading strategy for this paginated list
|
private static java.lang.String |
UNMODIFIABLE_MESSAGE |
Constructor and Description |
---|
PaginatedList(DynamoDBMapper mapper,
java.lang.Class<T> clazz,
AmazonDynamoDB dynamo)
Constructs a PaginatedList instance using the default PaginationLoadingStrategy
|
PaginatedList(DynamoDBMapper mapper,
java.lang.Class<T> clazz,
AmazonDynamoDB dynamo,
DynamoDBMapperConfig.PaginationLoadingStrategy paginationLoadingStrategy)
Constructs a PaginatedList instance.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int arg0,
T arg1) |
boolean |
add(T arg0) |
boolean |
addAll(java.util.Collection<? extends T> arg0) |
boolean |
addAll(int arg0,
java.util.Collection<? extends T> arg1) |
protected abstract boolean |
atEndOfResults()
Returns whether we have reached the end of the result set.
|
private void |
checkUnsupportedOperationForIterationOnlyMode(java.lang.String methodSignature) |
void |
clear() |
boolean |
contains(java.lang.Object arg0)
Returns whether the collection contains the given element.
|
boolean |
containsAll(java.util.Collection<?> arg0) |
protected abstract java.util.List<T> |
fetchNextPage()
Fetches the next page of results (which may be empty) and returns any
items found.
|
T |
get(int n)
Returns the Nth element of the list.
|
int |
indexOf(java.lang.Object arg0)
Returns the first index of the object given in the list.
|
boolean |
isEmpty()
Returns whether the collection is empty.
|
java.util.Iterator<T> |
iterator()
Returns an iterator over this list that lazily initializes results as
necessary.
|
int |
lastIndexOf(java.lang.Object arg0) |
java.util.ListIterator<T> |
listIterator() |
java.util.ListIterator<T> |
listIterator(int arg0) |
void |
loadAllResults()
Eagerly loads all results for this list.
|
private boolean |
loadNextResults()
Attempts to load the next batch of results, if there are any, into the
nextResults buffer.
|
private void |
moveNextResults(boolean clearPreviousResults)
Moves the contents of the nextResults buffer into allResults and resets
the buffer.
|
private boolean |
nextResultsAvailable()
Returns whether there are more results available not yet included in the
allResults member field.
|
T |
remove(int arg0) |
boolean |
remove(java.lang.Object arg0) |
boolean |
removeAll(java.util.Collection<?> arg0) |
boolean |
retainAll(java.util.Collection<?> arg0) |
T |
set(int arg0,
T arg1) |
int |
size() |
java.util.List<T> |
subList(int arg0,
int arg1)
Returns a sub-list in the range specified, loading more results as
necessary.
|
java.lang.Object[] |
toArray() |
<X> X[] |
toArray(X[] a) |
private static final java.lang.String UNMODIFIABLE_MESSAGE
private static final java.lang.String ITERATION_ONLY_UNSUPPORTED_OPERATION_MESSAGE
protected final DynamoDBMapper mapper
protected final java.lang.Class<T> clazz
protected final AmazonDynamoDB dynamo
protected boolean allResultsLoaded
protected final java.util.List<T> allResults
protected final java.util.List<T> nextResults
private final DynamoDBMapperConfig.PaginationLoadingStrategy paginationLoadingStrategy
private boolean iterationStarted
public PaginatedList(DynamoDBMapper mapper, java.lang.Class<T> clazz, AmazonDynamoDB dynamo)
public PaginatedList(DynamoDBMapper mapper, java.lang.Class<T> clazz, AmazonDynamoDB dynamo, DynamoDBMapperConfig.PaginationLoadingStrategy paginationLoadingStrategy)
mapper
- The mapper for marshalling DynamoDB attributes into objects.clazz
- The class of the annotated model.dynamo
- The DynamoDB client for making low-level request calls.paginationLoadingStrategy
- The strategy used for loading paginated results. Caller has to
explicitly set this parameter, since the DynamoDBMapperConfig
set in the mapper is not accessible here. If null value is
provided, LAZY_LOADING will be set by default.public void loadAllResults()
Not supported in ITERATION_ONLY mode.
private boolean nextResultsAvailable()
private boolean loadNextResults()
private void moveNextResults(boolean clearPreviousResults)
clearPreviousResults
- Whether it should clear previous results in allResults field.protected abstract java.util.List<T> fetchNextPage()
protected abstract boolean atEndOfResults()
public java.util.Iterator<T> iterator()
If it configured with ITERARTION_ONLY mode, then the iterator could be only retrieved once, and any previously loaded results will be cleared in the memory during the iteration.
public boolean isEmpty()
Not supported in ITERATION_ONLY mode.
public T get(int n)
Not supported in ITERATION_ONLY mode.
get
in interface java.util.List<T>
public boolean contains(java.lang.Object arg0)
Not supported in ITERATION_ONLY mode.
public java.util.List<T> subList(int arg0, int arg1)
Not supported in ITERATION_ONLY mode.
subList
in interface java.util.List<T>
public int indexOf(java.lang.Object arg0)
Not supported in ITERATION_ONLY mode.
indexOf
in interface java.util.List<T>
public int size()
public boolean containsAll(java.util.Collection<?> arg0)
public int lastIndexOf(java.lang.Object arg0)
lastIndexOf
in interface java.util.List<T>
public java.lang.Object[] toArray()
public <X> X[] toArray(X[] a)
public java.util.ListIterator<T> listIterator()
listIterator
in interface java.util.List<T>
public java.util.ListIterator<T> listIterator(int arg0)
listIterator
in interface java.util.List<T>
public boolean remove(java.lang.Object arg0)
public boolean removeAll(java.util.Collection<?> arg0)
public boolean retainAll(java.util.Collection<?> arg0)
public boolean add(T arg0)
public boolean addAll(java.util.Collection<? extends T> arg0)
public boolean addAll(int arg0, java.util.Collection<? extends T> arg1)
addAll
in interface java.util.List<T>
public void clear()
private void checkUnsupportedOperationForIterationOnlyMode(java.lang.String methodSignature)