diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/delete/DeleteConflictList.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/delete/DeleteConflictList.java index 24a44b7fccd..b925a81a25d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/delete/DeleteConflictList.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/delete/DeleteConflictList.java @@ -23,6 +23,7 @@ package ca.uhn.fhir.jpa.delete; import ca.uhn.fhir.jpa.util.DeleteConflict; import org.apache.commons.lang3.Validate; import org.hl7.fhir.instance.model.api.IIdType; +import org.springframework.util.Assert; import java.util.ArrayList; import java.util.HashSet; @@ -81,19 +82,30 @@ public class DeleteConflictList implements Iterable { private final int myOriginalRemoveModCont = myRemoveModCount; private int myNextIndex = 0; + private boolean myLastOperationWasNext; @Override public boolean hasNext() { checkForCoModification(); + myLastOperationWasNext = false; return myNextIndex < myList.size(); } @Override public DeleteConflict next() { checkForCoModification(); + myLastOperationWasNext = true; return myList.get(myNextIndex++); } + @Override + public void remove() { + Assert.isTrue(myLastOperationWasNext); + myNextIndex--; + myList.remove(myNextIndex); + myLastOperationWasNext = false; + } + private void checkForCoModification() { Validate.isTrue(myOriginalRemoveModCont == myRemoveModCount); }