Fixed error.

The order of checking for null prioritizing was swapped.
This commit is contained in:
Harrison Deng 2020-04-29 16:28:24 -05:00
parent 6f27e52c6b
commit 4c93e85078

View File

@ -2,8 +2,6 @@ package ca.recrown.islandsurvivalcraft.caching;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
public class Cache<K, V> { public class Cache<K, V> {
private final int maxSize; private final int maxSize;
@ -56,8 +54,8 @@ public class Cache<K, V> {
*/ */
public V get(K key) { public V get(K key) {
CacheValue<K, V> value = data.get(key); CacheValue<K, V> value = data.get(key);
usage.tryMoveToTop(value);
if (value == null) return null; if (value == null) return null;
usage.tryMoveToTop(value);
return value.value; return value.value;
} }