@Test public void testZeroSize() { try { new CallSemaphore().setMaxPermits(0); fail(); } catch (IllegalArgumentException e) { assertEquals("Semaphore size must be at least 1, was 0", e.getMessage()); } }
synchronized void setMaxPermits(int newMax) { if (newMax < 1) { throw new IllegalArgumentException("Semaphore size must be at least 1, was " + newMax); } int delta = newMax - this.maxPermits; if (delta == 0) { return; } else if (delta > 0) { logger.debug("Increasing size by " + delta + " to " + newMax); this.semaphore.release(delta); } else { delta *= -1; logger.debug("Decreasing size by " + delta + " to " + newMax); this.semaphore.reducePermits(delta); } this.maxPermits = newMax; }
CallSemaphore { synchronized void setMaxPermits(int newMax) { if (newMax < 1) { throw new IllegalArgumentException("Semaphore size must be at least 1, was " + newMax); } int delta = newMax - this.maxPermits; if (delta == 0) { return; } else if (delta > 0) { logger.debug("Increasing size by " + delta + " to " + newMax); this.semaphore.release(delta); } else { delta *= -1; logger.debug("Decreasing size by " + delta + " to " + newMax); this.semaphore.reducePermits(delta); } this.maxPermits = newMax; } }
CallSemaphore { synchronized void setMaxPermits(int newMax) { if (newMax < 1) { throw new IllegalArgumentException("Semaphore size must be at least 1, was " + newMax); } int delta = newMax - this.maxPermits; if (delta == 0) { return; } else if (delta > 0) { logger.debug("Increasing size by " + delta + " to " + newMax); this.semaphore.release(delta); } else { delta *= -1; logger.debug("Decreasing size by " + delta + " to " + newMax); this.semaphore.reducePermits(delta); } this.maxPermits = newMax; }  }
CallSemaphore { synchronized void setMaxPermits(int newMax) { if (newMax < 1) { throw new IllegalArgumentException("Semaphore size must be at least 1, was " + newMax); } int delta = newMax - this.maxPermits; if (delta == 0) { return; } else if (delta > 0) { logger.debug("Increasing size by " + delta + " to " + newMax); this.semaphore.release(delta); } else { delta *= -1; logger.debug("Decreasing size by " + delta + " to " + newMax); this.semaphore.reducePermits(delta); } this.maxPermits = newMax; }   }
CallSemaphore { synchronized void setMaxPermits(int newMax) { if (newMax < 1) { throw new IllegalArgumentException("Semaphore size must be at least 1, was " + newMax); } int delta = newMax - this.maxPermits; if (delta == 0) { return; } else if (delta > 0) { logger.debug("Increasing size by " + delta + " to " + newMax); this.semaphore.release(delta); } else { delta *= -1; logger.debug("Decreasing size by " + delta + " to " + newMax); this.semaphore.reducePermits(delta); } this.maxPermits = newMax; }    }