int (final int actualLength, final int currentCapacity) { if (actualLength < 0) { throw new IllegalArgumentException("actualLength(=" + actualLength + " should be >=0"); } if (currentCapacity < actualLength) { throw new IllegalArgumentException("currentCapacity(=" + currentCapacity + ") should be >= actualLength(=" + actualLength + ")"); } final double capacity = Math.ceil(actualLength * (1.0 + percentOnTheTop / 100.0)); final int advisedCapacity = (int)Math.max(minCapacity, capacity); if (advisedCapacity < 0 || advisedCapacity > maxCapacity) { return maxCapacity; } return advisedCapacity; }