diff --git a/pom.xml b/pom.xml index ac181e9..c940564 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ com.rsscripting RS-Warehouse RS-Warehouse - 1.1.0 + 1.2.0 21 diff --git a/src/main/java/com/rsscripting/rswarehouse/item/ItemsPagination.java b/src/main/java/com/rsscripting/rswarehouse/item/ItemsPagination.java index 06d0465..643a3d0 100644 --- a/src/main/java/com/rsscripting/rswarehouse/item/ItemsPagination.java +++ b/src/main/java/com/rsscripting/rswarehouse/item/ItemsPagination.java @@ -19,6 +19,7 @@ public class ItemsPagination { int highestAssignedPage = -1; int unassigned = 0; + int lastPageHighestSlot = 8; for (WarehouseItem item : items) { @@ -46,52 +47,52 @@ public class ItemsPagination { } - int consumed = 0; + if (highestAssignedPage < 0) { - for (int assignedPage = 0; - assignedPage <= highestAssignedPage; - assignedPage++) { + int pages = + (unassigned + 44) / 45; - int highestSlot = 8; - - for (WarehouseItem item : items) { - - if ( - item.page() != null - && - item.slot() != null - && - item.page() == assignedPage + 1 - ) { - - highestSlot = - Math.max( - highestSlot, - item.slot() - ); - - } - - } - - consumed += - Math.max( - 0, - 53 - highestSlot - ); + return Math.max( + 0, + pages - 1 + ); } - consumed = - Math.min( - consumed, - unassigned + for (WarehouseItem item : items) { + + if ( + item.page() != null + && + item.slot() != null + && + item.page() == highestAssignedPage + 1 + ) { + + lastPageHighestSlot = + Math.max( + lastPageHighestSlot, + item.slot() + ); + + } + + } + + int availableOnLastAssignedPage = + Math.max( + 0, + 53 - lastPageHighestSlot ); - unassigned -= consumed; + int remainingUnassigned = + Math.max( + 0, + unassigned - availableOnLastAssignedPage + ); int overflowPages = - (unassigned + 44) / 45; + (remainingUnassigned + 44) / 45; return Math.max( 0, @@ -175,59 +176,27 @@ public class ItemsPagination { } /* - * Figure out how many unassigned items have - * already been consumed by previous assigned pages. + * Unassigned items begin only on the last assigned page. */ - int consumed = 0; + if (page == highestAssignedPage) { - for (int previousPage = 0; - previousPage < page; - previousPage++) { - - int previousHighestSlot = 8; - - for (WarehouseItem item : assigned) { - - if (item.page() == (previousPage + 1)) { - - previousHighestSlot = - Math.max( - previousHighestSlot, - item.slot() - ); - - } - - } - - consumed += + int remainingSlots = Math.max( 0, - 53 - previousHighestSlot + 53 - highestSlot ); - } + for (int i = 0; + i < remainingSlots && i < unassigned.size(); + i++) { - int remainingSlots = - Math.max( - 0, - 53 - highestSlot + results.add( + unassigned.get( + i + ) ); - while ( - remainingSlots > 0 - && - consumed < unassigned.size() - ) { - - results.add( - unassigned.get( - consumed - ) - ); - - consumed++; - remainingSlots--; + } } @@ -235,46 +204,37 @@ public class ItemsPagination { } - int consumed = 0; + /* + * Overflow pages contain only unassigned items. + */ + int lastPageHighestSlot = 8; - for (int assignedPage = 0; - assignedPage <= highestAssignedPage; - assignedPage++) { + for (WarehouseItem item : assigned) { - int highestSlot = 8; + if (item.page() == highestAssignedPage + 1) { - for (WarehouseItem item : assigned) { - - if (item.page() == assignedPage + 1) { - - highestSlot = - Math.max( - highestSlot, - item.slot() - ); - - } + lastPageHighestSlot = + Math.max( + lastPageHighestSlot, + item.slot() + ); } - consumed += - Math.max( - 0, - 53 - highestSlot - ); - } + int consumed = + Math.max( + 0, + 53 - lastPageHighestSlot + ); + consumed = Math.min( consumed, unassigned.size() ); - /* - * Overflow pages - */ - int overflowPage = page - highestAssignedPage