@Test public void testGetIfPresent() { assertNull(stringDoubler.getIfPresent("10"), "Cache should be empty"); assertEquals(stringDoubler.getUnchecked("10"), Integer.valueOf(20), "Cache should load value for '10'"); assertEquals(stringDoubler.getIfPresent("10"), Integer.valueOf(20), "Cache should load value for '10'"); assertNull(stringDoubler.getIfPresent("20"), "Cache should have no value for '20'"); assertNull(stringDoubler.getIfPresent(new Object()), "Cache should have no value for arbitrary Object"); }
@Override public V getIfPresent(Object key) { try { @SuppressWarnings("unchecked") A cast = (A) key; return delegate().getIfPresent(keyTransformer().apply(cast)); } catch (ClassCastException e) { return null; } }
KeyTransformingLoadingCache extends AbstractLoadingCache<A, V> { @Override public V getIfPresent(Object key) { try { @SuppressWarnings("unchecked") A cast = (A) key; return delegate().getIfPresent(keyTransformer().apply(cast)); } catch (ClassCastException e) { return null; } } }
KeyTransformingLoadingCache extends AbstractLoadingCache<A, V> { @Override public V getIfPresent(Object key) { try { @SuppressWarnings("unchecked") A cast = (A) key; return delegate().getIfPresent(keyTransformer().apply(cast)); } catch (ClassCastException e) { return null; } } KeyTransformingLoadingCache(LoadingCache<B, V> delegate, Function<A, B> keyTransformer); }
KeyTransformingLoadingCache extends AbstractLoadingCache<A, V> { @Override public V getIfPresent(Object key) { try { @SuppressWarnings("unchecked") A cast = (A) key; return delegate().getIfPresent(keyTransformer().apply(cast)); } catch (ClassCastException e) { return null; } } KeyTransformingLoadingCache(LoadingCache<B, V> delegate, Function<A, B> keyTransformer); static KeyTransformingLoadingCache<A, B, V> from(LoadingCache<B, V> delegate, Function<A, B> keyTransformer); @Override V getIfPresent(Object key); @Override V get(A key, Callable<? extends V> valueLoader); @Override ImmutableMap<A, V> getAllPresent(Iterable<?> keys); @Override void put(A key, V value); @Override void invalidate(Object key); @Override void invalidateAll(); @Override long size(); @Override CacheStats stats(); @Override V get(A key); @Override void refresh(A key); @Override ConcurrentMap<A, V> asMap(); @Override void cleanUp(); }
KeyTransformingLoadingCache extends AbstractLoadingCache<A, V> { @Override public V getIfPresent(Object key) { try { @SuppressWarnings("unchecked") A cast = (A) key; return delegate().getIfPresent(keyTransformer().apply(cast)); } catch (ClassCastException e) { return null; } } KeyTransformingLoadingCache(LoadingCache<B, V> delegate, Function<A, B> keyTransformer); static KeyTransformingLoadingCache<A, B, V> from(LoadingCache<B, V> delegate, Function<A, B> keyTransformer); @Override V getIfPresent(Object key); @Override V get(A key, Callable<? extends V> valueLoader); @Override ImmutableMap<A, V> getAllPresent(Iterable<?> keys); @Override void put(A key, V value); @Override void invalidate(Object key); @Override void invalidateAll(); @Override long size(); @Override CacheStats stats(); @Override V get(A key); @Override void refresh(A key); @Override ConcurrentMap<A, V> asMap(); @Override void cleanUp();  }