Class OrderAction<T,M extends OrderAction<T,M>>
- java.lang.Object
-
- net.dv8tion.jda.core.requests.RestAction<java.lang.Void>
-
- net.dv8tion.jda.core.requests.restaction.order.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!
- Direct Known Subclasses:
ChannelOrderAction
,RoleOrderAction
public abstract class OrderAction<T,M extends OrderAction<T,M>> extends RestAction<java.lang.Void>
Extension ofRestAction
- Type: Void that allows to modify the order of entities provided as anArrayList
.
This action contains a List or entities for the specified typeT
which can be moved within the bounds but not removed, nor can any new entities be added.- Since:
- 3.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.dv8tion.jda.core.requests.RestAction
RestAction.EmptyRestAction<T>
-
-
Field Summary
-
Fields inherited from class net.dv8tion.jda.core.requests.RestAction
DEFAULT_FAILURE, DEFAULT_SUCCESS, LOG
-
-
Constructor Summary
Constructors Constructor Description OrderAction(JDA api, boolean ascendingOrder, net.dv8tion.jda.core.requests.Route.CompiledRoute route)
Creates a new OrderAction instanceOrderAction(JDA api, net.dv8tion.jda.core.requests.Route.CompiledRoute route)
Creates a new OrderAction instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<T>
getCurrentOrder()
Immutable List representing the currently selected order of entities in this OrderAction instanceT
getSelectedEntity()
The entity which is currently at theselected position
int
getSelectedPosition()
The currently selected position that is in focus for all modification operations of this OrderAction instanceM
moveDown(int amount)
Moves the currently selected entityamount
positions DOWN in order by pushing all entities up by one position.M
moveTo(int position)
Moves the currently selected entity to the specified position (0 based index).M
moveUp(int amount)
Moves the currently selected entityamount
positions UP in order by pushing all entities down by one position.M
reverseOrder()
Reverses thecurrent order
by usingCollections.reverse(orderList)
M
selectPosition(int selectedPosition)
Selects a new current entity at the specified index
This index is in correlation to thecurrent order
M
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)
internallyM
setCheck(java.util.function.BooleanSupplier checks)
Sets the last-second checks before finally executing the http request in the queue.M
shuffleOrder()
Shuffles thecurrent order
by usingCollections.shuffle(orderList)
M
sortOrder(java.util.Comparator<T> comparator)
Sorts thecurrent order
based on the specifiedComparator
.M
swapPosition(int swapPosition)
Swaps the currently selected entity with the entity located at the specified position.M
swapPosition(T swapEntity)
Swaps the currently selected entity with the specified entity.-
Methods inherited from class net.dv8tion.jda.core.requests.RestAction
complete, complete, completeAfter, getJDA, isPassContext, queue, queue, queue, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, setPassContext, submit, submit, submitAfter, submitAfter
-
-
-
-
Constructor Detail
-
OrderAction
public OrderAction(JDA api, net.dv8tion.jda.core.requests.Route.CompiledRoute route)
Creates a new OrderAction instance- Parameters:
api
- JDA instance which is associated with the entities contained in the order listroute
- TheCompiledRoute
which is provided to theRestAction Constructor
-
OrderAction
public OrderAction(JDA api, boolean ascendingOrder, net.dv8tion.jda.core.requests.Route.CompiledRoute route)
Creates a new OrderAction instance- Parameters:
api
- JDA instance which is associated with the entities contained in the order listascendingOrder
- Whether or not the order of items should be ascendingroute
- TheCompiledRoute
which is provided to theRestAction Constructor
-
-
Method Detail
-
setCheck
public M setCheck(java.util.function.BooleanSupplier checks)
Description copied from class: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.- Overrides:
setCheck
in classRestAction<java.lang.Void>
- Parameters:
checks
- The checks to run before executing the request, ornull
to run no checks- Returns:
- The current RestAction for chaining convenience
-
getCurrentOrder
public java.util.List<T> getCurrentOrder()
Immutable List representing the currently selected order of entities in this OrderAction instance- Returns:
- Immutable List representing the current order
-
selectPosition
public M selectPosition(int selectedPosition)
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:
java.lang.IllegalArgumentException
- If the provided position is out-of-bounds- See Also:
getSelectedPosition()
,getSelectedEntity()
-
selectPosition
public M 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)
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:
selectPosition(int)
,getSelectedPosition()
,getSelectedEntity()
-
getSelectedPosition
public 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
public T getSelectedEntity()
The entity which is currently at theselected position
- Returns:
- The currently selected entity
- Throws:
java.lang.IllegalStateException
- If no entity has been selected yet
-
moveUp
public M moveUp(int amount)
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:
java.lang.IllegalStateException
- If no entity has been selected yetjava.lang.IllegalArgumentException
- If the specified amount would cause the entity to go out-of-bounds- See Also:
moveTo(int)
-
moveDown
public M moveDown(int amount)
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:
java.lang.IllegalStateException
- If no entity has been selected yetjava.lang.IllegalArgumentException
- If the specified amount would cause the entity to go out-of-bounds- See Also:
moveTo(int)
-
moveTo
public M moveTo(int position)
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:
java.lang.IllegalStateException
- If no entity has been selected yetjava.lang.IllegalArgumentException
- If the specified position is out-of-bounds- See Also:
moveDown(int)
,moveUp(int)
-
swapPosition
public M swapPosition(int 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:
java.lang.IllegalStateException
- If no entity has been selected yetjava.lang.IllegalArgumentException
- If the specified position is out-of-bounds
-
swapPosition
public M swapPosition(T swapEntity)
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:
java.lang.IllegalStateException
- If no entity has been selected yetjava.lang.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:
swapPosition(int)
-
reverseOrder
public M reverseOrder()
Reverses thecurrent order
by usingCollections.reverse(orderList)
- Returns:
- The current OrderAction sub-implementation instance
- See Also:
Collections.reverse(java.util.List)
-
shuffleOrder
public M shuffleOrder()
Shuffles thecurrent order
by usingCollections.shuffle(orderList)
- Returns:
- The current OrderAction sub-implementation instance
- See Also:
Collections.shuffle(java.util.List)
-
sortOrder
public M sortOrder(java.util.Comparator<T> comparator)
- Parameters:
comparator
- Comparator used to sort the current order- Returns:
- The current OrderAction sub-implementation instance
- Throws:
java.lang.IllegalArgumentException
- If the specified comparator isnull
- See Also:
ArrayList.sort(java.util.Comparator)
-
-