@Test(expected = BufferAllocationException.class) public void testBeyondIntRange() { resizer = new BoundedProportionalArraySizingStrategy(); resizer.grow( BoundedProportionalArraySizingStrategy.MAX_ARRAY_LENGTH, BoundedProportionalArraySizingStrategy.MAX_ARRAY_LENGTH, 1); }
public int grow(int currentBufferLength, int elementsCount, int expectedAdditions) { long growBy = (long) ((long) currentBufferLength * growRatio); growBy = Math.max(growBy, minGrowCount); growBy = Math.min(growBy, maxGrowCount); long growTo = Math.min(MAX_ARRAY_LENGTH, growBy + currentBufferLength); long newSize = Math.max((long) elementsCount + expectedAdditions, growTo); if (newSize > MAX_ARRAY_LENGTH) { throw new BufferAllocationException( "Java array size exceeded (current length: %d, elements: %d, expected additions: %d)", currentBufferLength, elementsCount, expectedAdditions); } return (int) newSize; }
BoundedProportionalArraySizingStrategy implements ArraySizingStrategy { public int grow(int currentBufferLength, int elementsCount, int expectedAdditions) { long growBy = (long) ((long) currentBufferLength * growRatio); growBy = Math.max(growBy, minGrowCount); growBy = Math.min(growBy, maxGrowCount); long growTo = Math.min(MAX_ARRAY_LENGTH, growBy + currentBufferLength); long newSize = Math.max((long) elementsCount + expectedAdditions, growTo); if (newSize > MAX_ARRAY_LENGTH) { throw new BufferAllocationException( "Java array size exceeded (current length: %d, elements: %d, expected additions: %d)", currentBufferLength, elementsCount, expectedAdditions); } return (int) newSize; } }
BoundedProportionalArraySizingStrategy implements ArraySizingStrategy { public int grow(int currentBufferLength, int elementsCount, int expectedAdditions) { long growBy = (long) ((long) currentBufferLength * growRatio); growBy = Math.max(growBy, minGrowCount); growBy = Math.min(growBy, maxGrowCount); long growTo = Math.min(MAX_ARRAY_LENGTH, growBy + currentBufferLength); long newSize = Math.max((long) elementsCount + expectedAdditions, growTo); if (newSize > MAX_ARRAY_LENGTH) { throw new BufferAllocationException( "Java array size exceeded (current length: %d, elements: %d, expected additions: %d)", currentBufferLength, elementsCount, expectedAdditions); } return (int) newSize; } BoundedProportionalArraySizingStrategy();  BoundedProportionalArraySizingStrategy(int minGrow, int maxGrow, float ratio); }
BoundedProportionalArraySizingStrategy implements ArraySizingStrategy { public int grow(int currentBufferLength, int elementsCount, int expectedAdditions) { long growBy = (long) ((long) currentBufferLength * growRatio); growBy = Math.max(growBy, minGrowCount); growBy = Math.min(growBy, maxGrowCount); long growTo = Math.min(MAX_ARRAY_LENGTH, growBy + currentBufferLength); long newSize = Math.max((long) elementsCount + expectedAdditions, growTo); if (newSize > MAX_ARRAY_LENGTH) { throw new BufferAllocationException( "Java array size exceeded (current length: %d, elements: %d, expected additions: %d)", currentBufferLength, elementsCount, expectedAdditions); } return (int) newSize; } BoundedProportionalArraySizingStrategy();  BoundedProportionalArraySizingStrategy(int minGrow, int maxGrow, float ratio); int grow(int currentBufferLength, int elementsCount, int expectedAdditions); }
BoundedProportionalArraySizingStrategy implements ArraySizingStrategy { public int grow(int currentBufferLength, int elementsCount, int expectedAdditions) { long growBy = (long) ((long) currentBufferLength * growRatio); growBy = Math.max(growBy, minGrowCount); growBy = Math.min(growBy, maxGrowCount); long growTo = Math.min(MAX_ARRAY_LENGTH, growBy + currentBufferLength); long newSize = Math.max((long) elementsCount + expectedAdditions, growTo); if (newSize > MAX_ARRAY_LENGTH) { throw new BufferAllocationException( "Java array size exceeded (current length: %d, elements: %d, expected additions: %d)", currentBufferLength, elementsCount, expectedAdditions); } return (int) newSize; } BoundedProportionalArraySizingStrategy();  BoundedProportionalArraySizingStrategy(int minGrow, int maxGrow, float ratio); int grow(int currentBufferLength, int elementsCount, int expectedAdditions); static final int MAX_ARRAY_LENGTH; static final int DEFAULT_MIN_GROW_COUNT; static final int DEFAULT_MAX_GROW_COUNT; static final float DEFAULT_GROW_RATIO; final int minGrowCount; final int maxGrowCount; final float growRatio; }