M
- The current implementation used as chaining return valueT
- The type of entity to paginatepublic abstract class PaginationAction<T,M extends PaginationAction<T,M>> extends RestAction<java.util.List<T>> implements java.lang.Iterable<T>
RestAction
specification used
to retrieve entities for paginated endpoints (before, after, limit).Modifier and Type | Class and Description |
---|---|
class |
PaginationAction.PaginationIterator
Iterator implementation for a
PaginationAction . |
RestAction.EmptyRestAction<T>, RestAction.FailedRestAction<T>
DEFAULT_FAILURE, DEFAULT_SUCCESS, LOG
Constructor and Description |
---|
PaginationAction(JDA api)
Creates a new PaginationAction instance
This is used for PaginationActions that should not deal with limit(int) |
PaginationAction(JDA api,
net.dv8tion.jda.core.requests.Route.CompiledRoute route,
int minLimit,
int maxLimit,
int initialLimit)
Creates a new PaginationAction instance
|
Modifier and Type | Method and Description |
---|---|
M |
cache(boolean enableCache)
Whether already retrieved entities should be stored
within the internal cache.
|
int |
cacheSize()
The current amount of cached entities for this PaginationAction
|
java.util.List<T> |
getCached()
The currently cached entities of recent execution tasks.
|
T |
getFirst()
The first cached entity retrieved by this PaginationAction instance
|
T |
getLast()
The most recent entity retrieved by this PaginationAction instance
|
int |
getLimit()
The currently used limit.
|
int |
getMaxLimit()
The maximum limit that can be used for this PaginationAction
Limits provided to limit(int) must not be greater
than the returned value. |
int |
getMinLimit()
The minimum limit that can be used for this PaginationAction
Limits provided to limit(int) must not be less
than the returned value. |
boolean |
isCacheEnabled()
Whether retrieved entities are stored within an
internal cache.
|
boolean |
isEmpty()
Whether the cache of this PaginationAction is empty.
|
PaginationAction.PaginationIterator |
iterator()
PaginationIterator
that will iterate over all entities for this PaginationAction. |
M |
limit(int limit)
Sets the limit that should be used in the next RestAction completion
call.
|
java.util.stream.Stream<T> |
parallelStream()
Returns a possibly parallel
Stream with this PaginationAction as its
source. |
java.util.Spliterator<T> |
spliterator() |
java.util.stream.Stream<T> |
stream()
A sequential
Stream with this PaginationAction as its source. |
complete, complete, completeAfter, getJDA, queue, queue, queue, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, submit, submit, submitAfter, submitAfter
public PaginationAction(JDA api, net.dv8tion.jda.core.requests.Route.CompiledRoute route, int minLimit, int maxLimit, int initialLimit)
api
- The current JDA instanceroute
- The base routemaxLimit
- The inclusive maximum limit that can be used in limit(int)
minLimit
- The inclusive minimum limit that can be used in limit(int)
initialLimit
- The initial limit to use on the pagination endpointpublic PaginationAction(JDA api)
limit(int)
api
- The current JDA instancepublic int cacheSize()
public boolean isEmpty()
cacheSize() == 0
.public java.util.List<T> getCached()
RestAction
success
adds to this List. (Thread-Safe due to CopyOnWriteArrayList
)
This does not contain all entities for the paginated endpoint unless the pagination has reached an end!
It only contains those entities which already have been retrieved.
List
containing all currently cached entities for this PaginationActionpublic T getLast()
java.util.NoSuchElementException
- If no entities have been retrieved yet (see isEmpty()
)public T getFirst()
java.util.NoSuchElementException
- If no entities have been retrieved yet (see isEmpty()
)public M limit(int limit)
The specified limit may not be below the Minimum Limit
nor above
the Maximum Limit
. Unless these limits are specifically omitted. (See documentation of methods)
This limit represents how many entities will be retrieved per request and
NOT the maximum amount of entities that should be retrieved for iteration/sequencing.
action.limit(50).complete()
is not the same as
action.stream().limit(50).collect(collector)
limit
- The limit to usejava.lang.IllegalArgumentException
- If the provided limit is out of rangepublic M cache(boolean enableCache)
getCached()
.
Default: true
enableCache
- Whether to enable entity cachepublic boolean isCacheEnabled()
false
entities
retrieved by the iterator or a call to a RestAction
terminal operation will not be retrievable from getCached()
.
public final int getMaxLimit()
limit(int)
must not be greater
than the returned value.
0
.
That means there is no upper border for limiting this PaginationActionpublic final int getMinLimit()
limit(int)
must not be less
than the returned value.
0
.
That means there is no lower border for limiting this PaginationActionpublic final int getLimit()
0
@Nonnull public PaginationAction.PaginationIterator iterator()
PaginationIterator
that will iterate over all entities for this PaginationAction.iterator
in interface java.lang.Iterable<T>
public java.util.Spliterator<T> spliterator()
spliterator
in interface java.lang.Iterable<T>
public java.util.stream.Stream<T> stream()
Stream
with this PaginationAction as its source.Stream
over the elements in this PaginationActionpublic java.util.stream.Stream<T> parallelStream()
Stream
with this PaginationAction as its
source. It is allowable for this method to return a sequential stream.Stream
over the elements in this PaginationAction