@Nullable @Override public V get(@Nullable Object key) { if (key == null) { return null; } int hash = hash(key); return segmentFor(hash).get(key, hash); }
@Override public boolean remove(@Nullable Object key, @Nullable Object value) { if (key == null || value == null) { return false; } int hash = hash(key); return segmentFor(hash).remove(key, hash, value); }
@Nullable @Override public V remove(@Nullable Object key) { if (key == null) { return null; } int hash = hash(key); return segmentFor(hash).remove(key, hash); }
/** * This method is a convenience for testing. Code should call {@link Segment#copyEntry} directly. */ // Guarded By Segment.this @Nullable ReferenceEntry<K, V> copyEntry(@Nonnull ReferenceEntry<K, V> original, ReferenceEntry<K, V> newNext) { int hash = original.getHash(); return segmentFor(hash).copyEntry(original, newNext); }
/** * This method is a convenience for testing. Code should call {@link Segment#getLiveValue} * instead. */ boolean isLive(@Nonnull ReferenceEntry<K, V> entry, long now) { return segmentFor(entry.getHash()).getLiveValue(entry, now) != null; }
/** * Returns the internal entry for the specified key. The entry may be loading, expired, or * partially collected. */ @Nullable ReferenceEntry<K, V> getEntry(@Nullable Object key) { // does not impact recency ordering if (key == null) { return null; } int hash = hash(key); return segmentFor(hash).getEntry(key, hash); }
@Override public boolean containsKey(@Nullable Object key) { // does not impact recency ordering if (key == null) { return false; } int hash = hash(key); return segmentFor(hash).containsKey(key, hash); }
/** * This method is a convenience for testing. Code should call {@link Segment#setValue} instead. */ // Guarded By Segment.this @Nonnull ValueReference<K, V> newValueReference(@Nonnull ReferenceEntry<K, V> entry, @Nonnull V value, int weight) { int hash = entry.getHash(); return valueStrength.referenceValue(segmentFor(hash), entry, Preconditions.checkNotNull(value), weight); }
void reclaimKey(@Nonnull ReferenceEntry<K, V> entry) { int hash = entry.getHash(); segmentFor(hash).reclaimKey(entry, hash); }
@Nullable V get(@Nonnull K key, @Nonnull CacheLoader<? super K, V> loader) throws ExecutionException { int hash = hash(Preconditions.checkNotNull(key)); return segmentFor(hash).get(key, hash, loader); }
@Nullable public V getIfPresent(@Nonnull Object key) { int hash = hash(Preconditions.checkNotNull(key)); V value = segmentFor(hash).get(key, hash); if (value == null) { } else { } return value; }
/** * This method is a convenience for testing. Code should call {@link Segment#newEntry} directly. */ @Nonnull ReferenceEntry<K, V> newEntry(@Nonnull K key, int hash, ReferenceEntry<K, V> next) { Segment<K, V> segment = segmentFor(hash); segment.lock(); try { return segment.newEntry(key, hash, next); } finally { segment.unlock(); } }
@Nullable @Override public V put(@Nonnull K key, @Nonnull V value) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(value); int hash = hash(key); return segmentFor(hash).put(key, hash, value, false); }
@Override public boolean replace(@Nonnull K key, @Nullable V oldValue, @Nonnull V newValue) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(newValue); if (oldValue == null) { return false; } int hash = hash(key); return segmentFor(hash).replace(key, hash, oldValue, newValue); }
@Nullable @Override public V replace(@Nonnull K key, @Nonnull V value) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(value); int hash = hash(key); return segmentFor(hash).replace(key, hash, value); }
@Nullable @Override public V putIfAbsent(@Nonnull K key, @Nonnull V value) { Preconditions.checkNotNull(key); Preconditions.checkNotNull(value); int hash = hash(key); return segmentFor(hash).put(key, hash, value, true); }
void refresh(@Nonnull K key) { int hash = hash(Preconditions.checkNotNull(key)); segmentFor(hash).refresh(key, hash, defaultLoader, false); }
void reclaimValue(@Nonnull ValueReference<K, V> valueReference) { ReferenceEntry<K, V> entry = valueReference.getEntry(); int hash = entry.getHash(); segmentFor(hash).reclaimValue(entry.getKey(), hash, valueReference); }