@@ -746,8 +746,8 @@ public void updateItemQueues() {
746
746
continue ;
747
747
}
748
748
749
- for (ItemInfo itemInfo : items ) {
750
- this .addItemToProperQueue (itemInfo , currentTime );
749
+ for (Iterator < ItemInfo > it = items . iterator (); it . hasNext (); ) {
750
+ this .addItemToProperQueue (it . next () , currentTime , it );
751
751
}
752
752
}
753
753
@@ -767,10 +767,10 @@ public ItemStatus addItemToProperQueue(ItemInfo itemInfo, boolean is_loader) {
767
767
Timestamp baseTime = (is_loader ? this .getLoaderStartTime () : this .getCurrentTime ());
768
768
769
769
770
- return addItemToProperQueue (itemInfo , baseTime );
770
+ return addItemToProperQueue (itemInfo , baseTime , null );
771
771
}
772
772
773
- private ItemStatus addItemToProperQueue (ItemInfo itemInfo , Timestamp baseTime ) {
773
+ private ItemStatus addItemToProperQueue (ItemInfo itemInfo , Timestamp baseTime , Iterator < ItemInfo > currentQueueIterator ) {
774
774
// Always check whether we even want it for this client
775
775
// The loader's profile and the cache profile will always have a negative client_id,
776
776
// which means that we always want to keep it
@@ -799,30 +799,25 @@ private ItemStatus addItemToProperQueue(ItemInfo itemInfo, Timestamp baseTime) {
799
799
800
800
801
801
if (!new_status .equals (existingStatus )) {
802
+ // Remove the item from the current queue
803
+ if (currentQueueIterator != null ) {
804
+ currentQueueIterator .remove ();
805
+ }
806
+
802
807
switch (new_status ) {
803
808
case OPEN :
804
809
this .addItem (this .items_available , itemInfo );
805
810
break ;
806
811
case ENDING_SOON :
807
- this .items_available .remove (itemInfo );
808
812
this .addItem (this .items_endingSoon , itemInfo );
809
813
break ;
810
814
case WAITING_FOR_PURCHASE :
811
- (existingStatus == ItemStatus .OPEN ? this .items_available : this .items_endingSoon ).remove (itemInfo );
812
815
this .addItem (this .items_waitingForPurchase , itemInfo );
813
816
break ;
814
817
case CLOSED :
815
- if (existingStatus == ItemStatus .OPEN ) {
816
- this .items_available .remove (itemInfo );
817
- } else if (existingStatus == ItemStatus .ENDING_SOON ) {
818
- this .items_endingSoon .remove (itemInfo );
819
- } else {
820
- this .items_waitingForPurchase .remove (itemInfo );
821
- }
822
818
this .addItem (this .items_completed , itemInfo );
823
819
break ;
824
820
default :
825
-
826
821
}
827
822
itemInfo .setStatus (new_status );
828
823
}
0 commit comments