Skip to content

Commit

Permalink
Add missing exceptions when attempting to move entities before selecting
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 committed Feb 2, 2025
1 parent 4d372fd commit 043e168
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ public M moveTo(int position)
{
Checks.notNegative(position, "Provided position");
Checks.check(position < orderList.size(), "Provided position is too big and is out of bounds.");
if (selectedPosition == -1)
throw new IllegalStateException("Cannot move until an item has been selected. Use #selectPosition first.");

T selectedItem = orderList.remove(selectedPosition);
orderList.add(position, selectedItem);
Expand Down Expand Up @@ -250,6 +252,8 @@ public M swapPosition(int swapPosition)
Checks.notNegative(swapPosition, "Provided swapPosition");
Checks.check(swapPosition < orderList.size(), "Provided swapPosition is too big and is out of bounds. swapPosition: "
+ swapPosition);
if (selectedPosition == -1)
throw new IllegalStateException("Cannot move until an item has been selected. Use #selectPosition first.");

T selectedItem = orderList.get(selectedPosition);
T swapItem = orderList.get(swapPosition);
Expand Down

0 comments on commit 043e168

Please sign in to comment.