@Test public void cannotDoubleUnmarkMarkedResidues() { setupGeneratorWithModulus(3); requestResidues(3); unmarkResidue(0); assertThatThrownBy(() -> unmarkResidue(0)) .satisfies(DistributingModulusGeneratorTest::failureArisesFromUnmarkingResidues); }
public synchronized void unmarkResidue(int residue) { for (ReferenceCountedResidue referenceCountedResidue : referenceCounts) { if (referenceCountedResidue.residue() == residue) { Preconditions.checkState( referenceCountedResidue.references() > 0, "Attempted to unmark residue %s when it had no references", referenceCountedResidue.residue()); referenceCounts.remove(referenceCountedResidue); referenceCounts.add(referenceCountedResidue.unmark()); return; } } throw new IllegalStateException("Residue " + residue + " was not found when unmarking!"); }
DistributingModulusGenerator { public synchronized void unmarkResidue(int residue) { for (ReferenceCountedResidue referenceCountedResidue : referenceCounts) { if (referenceCountedResidue.residue() == residue) { Preconditions.checkState( referenceCountedResidue.references() > 0, "Attempted to unmark residue %s when it had no references", referenceCountedResidue.residue()); referenceCounts.remove(referenceCountedResidue); referenceCounts.add(referenceCountedResidue.unmark()); return; } } throw new IllegalStateException("Residue " + residue + " was not found when unmarking!"); } }
DistributingModulusGenerator { public synchronized void unmarkResidue(int residue) { for (ReferenceCountedResidue referenceCountedResidue : referenceCounts) { if (referenceCountedResidue.residue() == residue) { Preconditions.checkState( referenceCountedResidue.references() > 0, "Attempted to unmark residue %s when it had no references", referenceCountedResidue.residue()); referenceCounts.remove(referenceCountedResidue); referenceCounts.add(referenceCountedResidue.unmark()); return; } } throw new IllegalStateException("Residue " + residue + " was not found when unmarking!"); } DistributingModulusGenerator(int modulus); }
DistributingModulusGenerator { public synchronized void unmarkResidue(int residue) { for (ReferenceCountedResidue referenceCountedResidue : referenceCounts) { if (referenceCountedResidue.residue() == residue) { Preconditions.checkState( referenceCountedResidue.references() > 0, "Attempted to unmark residue %s when it had no references", referenceCountedResidue.residue()); referenceCounts.remove(referenceCountedResidue); referenceCounts.add(referenceCountedResidue.unmark()); return; } } throw new IllegalStateException("Residue " + residue + " was not found when unmarking!"); } DistributingModulusGenerator(int modulus); synchronized int getAndMarkResidue(); synchronized void unmarkResidue(int residue); }
DistributingModulusGenerator { public synchronized void unmarkResidue(int residue) { for (ReferenceCountedResidue referenceCountedResidue : referenceCounts) { if (referenceCountedResidue.residue() == residue) { Preconditions.checkState( referenceCountedResidue.references() > 0, "Attempted to unmark residue %s when it had no references", referenceCountedResidue.residue()); referenceCounts.remove(referenceCountedResidue); referenceCounts.add(referenceCountedResidue.unmark()); return; } } throw new IllegalStateException("Residue " + residue + " was not found when unmarking!"); } DistributingModulusGenerator(int modulus); synchronized int getAndMarkResidue(); synchronized void unmarkResidue(int residue);  }