EvictingArray { public T computeIfAbsent(long position, @NotNull final Function<Long, T> supplier) { if (minPosition == 0) { minPosition = (int) position - capacity + 1; } int distanceFromMinPosition = (int) position - minPosition; if (distanceFromMinPosition < 0) { throw new IllegalArgumentException("Cannot add position: " + position + " before min position: " + minPosition); } if (distanceFromMinPosition >= capacity) { flush((int) position - minPosition - capacity + 1); } distanceFromMinPosition = (int) position - minPosition; int index = (minPositionIndex + distanceFromMinPosition) & (elements.length - 1); T element = (T) elements[index]; if (element == null) { element = supplier.apply(position); elements[index] = element; } return element; } EvictingArray(int minCapacity, Consumer<T> evictionHandler); T computeIfAbsent(long position, @NotNull final Function<Long, T> supplier); int capacity(); void evictAll();  }
@Test(expected = IllegalArgumentException.class) public void testInsertEarlierThanMinCausesException() { testCapacityOverflow(); victim.computeIfAbsent(1000, EvictingArrayTest::create); }