T
- The entity type for the List
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!public abstract class OrderAction<T,M extends OrderAction<T,M>> extends RestAction<java.lang.Void>
RestAction
- Type: Void
that allows to modify the order of entities provided as an ArrayList
.
T
which
can be moved within the bounds but not removed, nor can any new entities be added.RestAction.EmptyRestAction<T>, RestAction.FailedRestAction<T>
DEFAULT_FAILURE, DEFAULT_SUCCESS, LOG
Constructor and Description |
---|
OrderAction(JDA api,
boolean ascendingOrder,
net.dv8tion.jda.core.requests.Route.CompiledRoute route)
Creates a new OrderAction instance
|
OrderAction(JDA api,
net.dv8tion.jda.core.requests.Route.CompiledRoute route)
Creates a new OrderAction instance
|
Modifier and Type | Method and Description |
---|---|
java.util.List<T> |
getCurrentOrder()
Immutable List representing the currently selected order
of entities in this OrderAction instance
|
JDA |
getJDA()
The corresponding JDA instance for the entities of
this OrderAction instance
|
T |
getSelectedEntity()
The entity which is currently at the
selected position |
int |
getSelectedPosition()
The currently selected position
that is in focus for all modification operations of this OrderAction instance
|
M |
moveDown(int amount)
Moves the currently selected entity
amount 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 entity
amount positions UP
in order by pushing all entities down by one position. |
M |
reverseOrder()
Reverses the
current order by using
Collections.reverse(orderList) |
M |
selectPosition(int selectedPosition)
Selects a new current entity at the specified index
This index is in correlation to the current order |
M |
selectPosition(T selectedEntity)
Selects a new current entity based on the index of
the specified entity in the
current order
This is a convenience function that uses selectPosition(int) internally |
M |
shuffleOrder()
Shuffles the
current order by using
Collections.shuffle(orderList) |
M |
sortOrder(java.util.Comparator<T> comparator)
Sorts the
current order based on
the specified Comparator . |
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.
|
complete, complete, completeAfter, queue, queue, queue, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, submit, submit, submitAfter, submitAfter
public OrderAction(JDA api, net.dv8tion.jda.core.requests.Route.CompiledRoute route)
api
- JDA instance which is associated with the entities contained
in the order listroute
- The CompiledRoute
which is provided to the RestAction Constructor
public OrderAction(JDA api, boolean ascendingOrder, net.dv8tion.jda.core.requests.Route.CompiledRoute route)
api
- JDA instance which is associated with the entities contained
in the order listascendingOrder
- Whether or not the order of items should be ascendingroute
- The CompiledRoute
which is provided to the RestAction Constructor
public JDA getJDA()
getJDA
in class RestAction<java.lang.Void>
public java.util.List<T> getCurrentOrder()
public M selectPosition(int selectedPosition)
current order
selectedPosition
- The index for the new position that will be in focus for all modification
operationsjava.lang.IllegalArgumentException
- If the provided position is out-of-boundsgetSelectedPosition()
,
getSelectedEntity()
public M selectPosition(T selectedEntity)
current order
selectPosition(int)
internallyselectedEntity
- The entity for the new position that will be in focus for all modification
operationsselectPosition(int)
,
getSelectedPosition()
,
getSelectedEntity()
public int getSelectedPosition()
public T getSelectedEntity()
selected position
java.lang.IllegalStateException
- If no entity has been selected yetpublic M moveUp(int amount)
amount
positions UP
in order by pushing all entities down by one position.amount
- The amount of positions that should be movedjava.lang.IllegalStateException
- If no entity has been selected yetjava.lang.IllegalArgumentException
- If the specified amount would cause the entity to go out-of-boundsmoveTo(int)
public M moveDown(int amount)
amount
positions DOWN
in order by pushing all entities up by one position.amount
- The amount of positions that should be movedjava.lang.IllegalStateException
- If no entity has been selected yetjava.lang.IllegalArgumentException
- If the specified amount would cause the entity to go out-of-boundsmoveTo(int)
public M moveTo(int position)
position
- The new not-negative position for the currently selected entityjava.lang.IllegalStateException
- If no entity has been selected yetjava.lang.IllegalArgumentException
- If the specified position is out-of-boundsmoveDown(int)
,
moveUp(int)
public M swapPosition(int swapPosition)
swapPosition
- 0 based index of target positionjava.lang.IllegalStateException
- If no entity has been selected yetjava.lang.IllegalArgumentException
- If the specified position is out-of-boundspublic M swapPosition(T swapEntity)
swapEntity
- Target entity to switch positions withjava.lang.IllegalStateException
- If no entity has been selected yetjava.lang.IllegalArgumentException
- If the specified position is out-of-bounds,
or if the target entity is null
or not
available in this order action implementationswapPosition(int)
public M reverseOrder()
current order
by using
Collections.reverse(orderList)
Collections.reverse(java.util.List)
public M shuffleOrder()
current order
by using
Collections.shuffle(orderList)
Collections.shuffle(java.util.List)
public M sortOrder(java.util.Comparator<T> comparator)
comparator
- Comparator used to sort the current orderjava.lang.IllegalArgumentException
- If the specified comparator is null
ArrayList.sort(java.util.Comparator)