Interface OrderAction<T,M extends OrderAction<T,M>>
- Type Parameters:
T
- The entity type for theList
of entities contained in the OrderAction's orderListM
- The extension implementing the abstract operations of this OrderAction, this will be important for chaining convenience as it returns the specific implementation rather than a mask of this class. It allows us to implement chaining operations in this class instead of having to implement it in every inheriting class!
- All Superinterfaces:
RestAction<Void>
- All Known Subinterfaces:
CategoryOrderAction
,ChannelOrderAction
,RoleOrderAction
Extension of
This action contains a List or entities for the specified type
RestAction
- Type: Void
that allows to modify the order of entities provided as an ArrayList
.
This action contains a List or entities for the specified type
T
which
can be moved within the bounds but not removed, nor can any new entities be added.- Since:
- 3.0
-
Method Summary
Modifier and TypeMethodDescriptiondeadline
(long timestamp) Similar toRestAction.timeout(long, TimeUnit)
but schedules a deadline at which the request has to be completed.Immutable List representing the currently selected order of entities in this OrderAction instanceThe entity which is currently at theselected position
int
The currently selected position that is in focus for all modification operations of this OrderAction instanceboolean
Whether this instance uses ascending order, from the lowest position to the highest.Moves the currently selected entity above the specified target entity.Moves the currently selected entity below the specified target entity.moveDown
(int amount) Moves the currently selected entityamount
positions DOWN in order by pushing all entities up by one position.moveTo
(int position) Moves the currently selected entity to the specified position (0 based index).moveUp
(int amount) Moves the currently selected entityamount
positions UP in order by pushing all entities down by one position.Reverses thecurrent order
by usingCollections.reverse(orderList)
selectPosition
(int selectedPosition) Selects a new current entity at the specified index
This index is in correlation to thecurrent order
selectPosition
(T selectedEntity) Selects a new current entity based on the index of the specified entity in thecurrent order
This is a convenience function that usesselectPosition(int)
internallysetCheck
(BooleanSupplier checks) Sets the last-second checks before finally executing the http request in the queue.Shuffles thecurrent order
by usingCollections.shuffle(orderList)
sortOrder
(Comparator<T> comparator) swapPosition
(int swapPosition) Swaps the currently selected entity with the entity located at the specified position.swapPosition
(T swapEntity) Swaps the currently selected entity with the specified entity.Timeout for this RestAction instance.Methods inherited from interface net.dv8tion.jda.api.requests.RestAction
addCheck, and, and, complete, complete, completeAfter, delay, delay, delay, delay, flatMap, flatMap, getCheck, getJDA, map, mapToResult, onErrorFlatMap, onErrorFlatMap, onErrorMap, onErrorMap, onSuccess, queue, queue, queue, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, submit, submit, submitAfter, submitAfter, zip
-
Method Details
-
setCheck
Description copied from interface:RestAction
Sets the last-second checks before finally executing the http request in the queue.
If the provided supplier evaluates tofalse
or throws an exception this will not be finished. When an exception is thrown from the supplier it will be provided to the failure callback.- Specified by:
setCheck
in interfaceRestAction<T>
- Parameters:
checks
- The checks to run before executing the request, ornull
to run no checks- Returns:
- The current RestAction for chaining convenience
- See Also:
-
timeout
Description copied from interface:RestAction
Timeout for this RestAction instance.
If the request doesn't get executed within the timeout it will fail.When a RestAction times out, it will fail with a
TimeoutException
. This is the same asdeadline(System.currentTimeMillis() + unit.toMillis(timeout))
.Example
action.timeout(10, TimeUnit.SECONDS) // 10 seconds from now .queueAfter(20, SECONDS); // request will not be executed within deadline and timeout immediately after 20 seconds
- Specified by:
timeout
in interfaceRestAction<T>
- Parameters:
timeout
- The timeout to useunit
-Unit
for the timeout value- Returns:
- The same RestAction instance with the applied timeout
- See Also:
-
deadline
Description copied from interface:RestAction
Similar toRestAction.timeout(long, TimeUnit)
but schedules a deadline at which the request has to be completed.
If the deadline is reached, the request will fail with aTimeoutException
.This does not mean that the request will immediately timeout when the deadline is reached. JDA will check the deadline right before executing the request or within intervals in a worker thread. This only means the request will timeout if the deadline has passed.
Example
action.deadline(System.currentTimeMillis() + 10000) // 10 seconds from now .queueAfter(20, SECONDS); // request will not be executed within deadline and timeout immediately after 20 seconds
- Specified by:
deadline
in interfaceRestAction<T>
- Parameters:
timestamp
- Millisecond timestamp at which the request will timeout- Returns:
- The same RestAction with the applied deadline
- See Also:
-
isAscendingOrder
boolean isAscendingOrder()Whether this instance uses ascending order, from the lowest position to the highest.- Returns:
- True, if this uses ascending order
-
getCurrentOrder
Immutable List representing the currently selected order of entities in this OrderAction instance- Returns:
- Immutable List representing the current order
-
selectPosition
Selects a new current entity at the specified index
This index is in correlation to thecurrent order
- Parameters:
selectedPosition
- The index for the new position that will be in focus for all modification operations- Returns:
- The current OrderAction sub-implementation instance
- Throws:
IllegalArgumentException
- If the provided position is out-of-bounds- See Also:
-
selectPosition
Selects a new current entity based on the index of the specified entity in thecurrent order
This is a convenience function that usesselectPosition(int)
internally- Parameters:
selectedEntity
- The entity for the new position that will be in focus for all modification operations- Returns:
- The current OrderAction sub-implementation instance
- See Also:
-
getSelectedPosition
int getSelectedPosition()The currently selected position that is in focus for all modification operations of this OrderAction instance- Returns:
- The currently selected index, or -1 if no position has been selected yet
-
getSelectedEntity
The entity which is currently at theselected position
- Returns:
- The currently selected entity
- Throws:
IllegalStateException
- If no entity has been selected yet, useselectPosition(Object)
-
moveUp
Moves the currently selected entityamount
positions UP in order by pushing all entities down by one position.- Parameters:
amount
- The amount of positions that should be moved- Returns:
- The current OrderAction sub-implementation instance
- Throws:
IllegalStateException
- If no entity has been selected yet, useselectPosition(Object)
IllegalArgumentException
- If the specified amount would cause the entity to go out-of-bounds- See Also:
-
moveDown
Moves the currently selected entityamount
positions DOWN in order by pushing all entities up by one position.- Parameters:
amount
- The amount of positions that should be moved- Returns:
- The current OrderAction sub-implementation instance
- Throws:
IllegalStateException
- If no entity has been selected yet, useselectPosition(Object)
IllegalArgumentException
- If the specified amount would cause the entity to go out-of-bounds- See Also:
-
moveTo
Moves the currently selected entity to the specified position (0 based index). All entities are moved in the direction of the left hole to fill the gap.- Parameters:
position
- The new not-negative position for the currently selected entity- Returns:
- The current OrderAction sub-implementation instance
- Throws:
IllegalStateException
- If no entity has been selected yet, useselectPosition(Object)
IllegalArgumentException
- If the specified position is out-of-bounds- See Also:
-
moveBelow
Moves the currently selected entity below the specified target entity.- Parameters:
other
- The reference entity that should end up above the selected entity- Returns:
- The current OrderAction sub-implementation instance
- Throws:
IllegalStateException
- If no entity has been selected yet, useselectPosition(Object)
IllegalArgumentException
- If the specified target entity is not managed by this instance or null- See Also:
-
moveAbove
Moves the currently selected entity above the specified target entity.- Parameters:
other
- The reference entity that should end up below the selected entity- Returns:
- The current OrderAction sub-implementation instance
- Throws:
IllegalStateException
- If no entity has been selected yet, useselectPosition(Object)
IllegalArgumentException
- If the specified target entity is not managed by this instance or null- See Also:
-
swapPosition
Swaps the currently selected entity with the entity located at the specified position. No other entities are affected by this operation.- Parameters:
swapPosition
- 0 based index of target position- Returns:
- The current OrderAction sub-implementation instance
- Throws:
IllegalStateException
- If no entity has been selected yet, useselectPosition(Object)
IllegalArgumentException
- If the specified position is out-of-bounds
-
swapPosition
Swaps the currently selected entity with the specified entity. No other entities are affected by this operation.- Parameters:
swapEntity
- Target entity to switch positions with- Returns:
- The current OrderAction sub-implementation instance
- Throws:
IllegalStateException
- If no entity has been selected yet, useselectPosition(Object)
IllegalArgumentException
- If the specified position is out-of-bounds, or if the target entity isnull
or not available in this order action implementation- See Also:
-
reverseOrder
Reverses thecurrent order
by usingCollections.reverse(orderList)
- Returns:
- The current OrderAction sub-implementation instance
- See Also:
-
shuffleOrder
Shuffles thecurrent order
by usingCollections.shuffle(orderList)
- Returns:
- The current OrderAction sub-implementation instance
- See Also:
-
sortOrder
- Parameters:
comparator
- Comparator used to sort the current order- Returns:
- The current OrderAction sub-implementation instance
- Throws:
IllegalArgumentException
- If the specified comparator isnull
- See Also:
-