@Test public void shouldCacheValues() { final AutoCloseable first = cache.lookup(1); final AutoCloseable second = cache.lookup(1); assertSame(lastValue, first); assertSame(lastValue, second); assertNotNull(lastValue); verifyOneConstructed(1); }
@SuppressWarnings("unchecked") public E lookup(final int key) { @DoNotSub int size = this.size; for (@DoNotSub int i = 0; i < size; i++) { if (keys[i] == key) { final E value = (E)values[i]; makeMostRecent(key, value, i); return value; } } final E value = factory.apply(key); if (value != null) { if (size == capacity) { closer.accept((E)values[size - 1]); } else { size++; this.size = size; } makeMostRecent(key, value, size - 1); } return value; }
IntLruCache implements AutoCloseable { @SuppressWarnings("unchecked") public E lookup(final int key) { @DoNotSub int size = this.size; for (@DoNotSub int i = 0; i < size; i++) { if (keys[i] == key) { final E value = (E)values[i]; makeMostRecent(key, value, i); return value; } } final E value = factory.apply(key); if (value != null) { if (size == capacity) { closer.accept((E)values[size - 1]); } else { size++; this.size = size; } makeMostRecent(key, value, size - 1); } return value; } }
IntLruCache implements AutoCloseable { @SuppressWarnings("unchecked") public E lookup(final int key) { @DoNotSub int size = this.size; for (@DoNotSub int i = 0; i < size; i++) { if (keys[i] == key) { final E value = (E)values[i]; makeMostRecent(key, value, i); return value; } } final E value = factory.apply(key); if (value != null) { if (size == capacity) { closer.accept((E)values[size - 1]); } else { size++; this.size = size; } makeMostRecent(key, value, size - 1); } return value; } IntLruCache(
        @DoNotSub final int capacity,
        final IntFunction<E> factory,
        final Consumer<E> closer); }
IntLruCache implements AutoCloseable { @SuppressWarnings("unchecked") public E lookup(final int key) { @DoNotSub int size = this.size; for (@DoNotSub int i = 0; i < size; i++) { if (keys[i] == key) { final E value = (E)values[i]; makeMostRecent(key, value, i); return value; } } final E value = factory.apply(key); if (value != null) { if (size == capacity) { closer.accept((E)values[size - 1]); } else { size++; this.size = size; } makeMostRecent(key, value, size - 1); } return value; } IntLruCache(
        @DoNotSub final int capacity,
        final IntFunction<E> factory,
        final Consumer<E> closer); @SuppressWarnings("unchecked") E lookup(final int key); @DoNotSub int capacity(); @SuppressWarnings("unchecked") void close(); }
IntLruCache implements AutoCloseable { @SuppressWarnings("unchecked") public E lookup(final int key) { @DoNotSub int size = this.size; for (@DoNotSub int i = 0; i < size; i++) { if (keys[i] == key) { final E value = (E)values[i]; makeMostRecent(key, value, i); return value; } } final E value = factory.apply(key); if (value != null) { if (size == capacity) { closer.accept((E)values[size - 1]); } else { size++; this.size = size; } makeMostRecent(key, value, size - 1); } return value; } IntLruCache(
        @DoNotSub final int capacity,
        final IntFunction<E> factory,
        final Consumer<E> closer); @SuppressWarnings("unchecked") E lookup(final int key); @DoNotSub int capacity(); @SuppressWarnings("unchecked") void close();  }