/** * * @param computingFunction * @return a new ComputingCache instance */ public <K, V> ComputingCache<K, V> build(Function<K, V> computingFunction) { if (weakValues) { return new ReentrantMapBackedComputingCache<>(computingFunction, WeakLazyValueHolder::forSupplier, maxSize); } return new ReentrantMapBackedComputingCache<>(computingFunction, maxSize); } }
@SuppressWarnings("unchecked") @Override public <T> T getCastValue(Object key) { return (T) getValue((K) key); }
@Override public V getValue(final K key) { ValueHolder<V> value = map.get(key); if (value == null) { value = function.apply(key); ValueHolder<V> previous = map.putIfAbsent(key, value); if (previous != null) { value = previous; } // finally, check that we are not over the bound if (maxSize != null && size() > maxSize) { clear(); } } return value.get(); }
@Override public V getValue(final K key) { ValueHolder<V> value = map.get(key); if (value == null) { value = function.apply(key); ValueHolder<V> previous = map.putIfAbsent(key, value); if (previous != null) { value = previous; } // finally, check that we are not over the bound if (maxSize != null && size() > maxSize) { clear(); } } return value.get(); }
@Override public V getValue(final K key) { ValueHolder<V> value = map.get(key); if (value == null) { value = function.apply(key); ValueHolder<V> previous = map.putIfAbsent(key, value); if (previous != null) { value = previous; } // finally, check that we are not over the bound if (maxSize != null && size() > maxSize) { clear(); } } return value.get(); }
/** * * @param computingFunction * @return a new ComputingCache instance */ public <K, V> ComputingCache<K, V> build(Function<K, V> computingFunction) { if (weakValues) { return new ReentrantMapBackedComputingCache<>(computingFunction, WeakLazyValueHolder::forSupplier, maxSize); } return new ReentrantMapBackedComputingCache<>(computingFunction, maxSize); } }
@SuppressWarnings("unchecked") @Override public <T> T getCastValue(Object key) { return (T) getValue((K) key); }
@Override public V getValue(final K key) { ValueHolder<V> value = map.get(key); if (value == null) { value = function.apply(key); ValueHolder<V> previous = map.putIfAbsent(key, value); if (previous != null) { value = previous; } // finally, check that we are not over the bound if (maxSize != null && size() > maxSize) { clear(); } } return value.get(); }
/** * * @param computingFunction * @return a new ComputingCache instance */ public <K, V> ComputingCache<K, V> build(Function<K, V> computingFunction) { if (weakValues) { return new ReentrantMapBackedComputingCache<>(computingFunction, WeakLazyValueHolder::forSupplier, maxSize); } return new ReentrantMapBackedComputingCache<>(computingFunction, maxSize); } }
@SuppressWarnings("unchecked") @Override public <T> T getCastValue(Object key) { return (T) getValue((K) key); }
@Override public V getValue(final K key) { ValueHolder<V> value = map.get(key); if (value == null) { value = function.apply(key); ValueHolder<V> previous = map.putIfAbsent(key, value); if (previous != null) { value = previous; } // finally, check that we are not over the bound if (maxSize != null && size() > maxSize) { clear(); } } return value.get(); }
/** * * @param computingFunction * @return a new ComputingCache instance */ public <K, V> ComputingCache<K, V> build(Function<K, V> computingFunction) { if (weakValues) { return new ReentrantMapBackedComputingCache<>(computingFunction, WeakLazyValueHolder::forSupplier, maxSize); } return new ReentrantMapBackedComputingCache<>(computingFunction, maxSize); } }
@SuppressWarnings("unchecked") @Override public <T> T getCastValue(Object key) { return (T) getValue((K) key); }
@Override public V getValue(final K key) { ValueHolder<V> value = map.get(key); if (value == null) { value = function.apply(key); ValueHolder<V> previous = map.putIfAbsent(key, value); if (previous != null) { value = previous; } // finally, check that we are not over the bound if (maxSize != null && size() > maxSize) { clear(); } } return value.get(); }
/** * * @param computingFunction * @return a new ComputingCache instance */ public <K, V> ComputingCache<K, V> build(Function<K, V> computingFunction) { if (weakValues) { return new ReentrantMapBackedComputingCache<>(computingFunction, WeakLazyValueHolder::forSupplier, maxSize); } return new ReentrantMapBackedComputingCache<>(computingFunction, maxSize); } }
@SuppressWarnings("unchecked") @Override public <T> T getCastValue(Object key) { return (T) getValue((K) key); }
/** * * @param computingFunction * @return a new ComputingCache instance */ public <K, V> ComputingCache<K, V> build(Function<K, V> computingFunction) { if (weakValues) { return new ReentrantMapBackedComputingCache<K, V>(computingFunction, WeakLazyValueHolder.<V>forValue(), maxSize); } return new ReentrantMapBackedComputingCache<K, V>(computingFunction, maxSize); } }
@SuppressWarnings("unchecked") @Override public <T> T getCastValue(Object key) { return (T) getValue((K) key); }