Ejemplo n.º 1
0
 private V putNewEntry(final K key, final V value) {
   final int position = strategy.getStorePosition();
   final MyWeakReference<K, V> reference = new MyWeakReference<K, V>(key, value, queue);
   final CacheSlot<K, V> old = accessMap.put(key, new CacheSlot<K, V>(position, reference));
   if (old != null && old.reference != null) old.reference.clearKey();
   if (cache[position] != null) {
     processReferenceQueue();
   }
   cache[position] = Pair.create(key, value);
   strategy.registerAccess(position);
   return value;
 }
Ejemplo n.º 2
0
 private V putEntryInSlot(
     final K key,
     final V value,
     final @NotNull CacheSlot<K, V> slot,
     final boolean alterCacheStrategy) {
   if (slot.reference != null) slot.reference.clearKey();
   slot.reference = new MyWeakReference<K, V>(key, value, queue);
   cache[slot.position] = Pair.create(key, value);
   if (alterCacheStrategy) {
     strategy.registerAccess(slot.position);
   }
   return value;
 }
Ejemplo n.º 3
0
 private boolean alterCacheStrategy(final K key, final Pair<K, V> atPosition) {
   return atPosition != null
       && (atPosition.getFirst() == key || atPosition.getFirst().equals(key));
 }