Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 6ba84e948 -> f409750b0


Generify LRUCache


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f409750b
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f409750b
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f409750b

Branch: refs/heads/GROOVY_2_6_X
Commit: f409750b0101947ee121eff681a942f60c60a841
Parents: 6ba84e9
Author: sunlan <[email protected]>
Authored: Tue Jan 9 16:08:39 2018 +0800
Committer: sunlan <[email protected]>
Committed: Tue Jan 9 16:08:39 2018 +0800

----------------------------------------------------------------------
 .../codehaus/groovy/runtime/memoize/LRUCache.java    | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f409750b/src/main/java/org/codehaus/groovy/runtime/memoize/LRUCache.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/memoize/LRUCache.java 
b/src/main/java/org/codehaus/groovy/runtime/memoize/LRUCache.java
index bf041ae..45d8099 100644
--- a/src/main/java/org/codehaus/groovy/runtime/memoize/LRUCache.java
+++ b/src/main/java/org/codehaus/groovy/runtime/memoize/LRUCache.java
@@ -23,6 +23,7 @@ import 
org.apache.groovy.util.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
 import java.lang.ref.SoftReference;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.concurrent.ConcurrentMap;
 
 /**
  * A cache backed by a ConcurrentLinkedHashMap
@@ -30,21 +31,21 @@ import java.util.Map;
  * @author Vaclav Pech
  * @author <a href="mailto:[email protected]";>Daniel.Sun</a>
  */
-public final class LRUCache implements MemoizeCache<Object, Object> {
-    private final Map<Object, Object> cache;
+public final class LRUCache<K, V> implements MemoizeCache<K, V> {
+    private final ConcurrentMap<K, V> cache;
 
     public LRUCache(final int maxCacheSize) {
 //        cache = Collections.synchronizedMap(new 
LRUProtectionStorage(maxCacheSize));
-        cache = new ConcurrentLinkedHashMap.Builder<>()
+        cache = new ConcurrentLinkedHashMap.Builder<K, V>()
                 .maximumWeightedCapacity(maxCacheSize)
                 .build();
     }
 
-    public Object put(final Object key, final Object value) {
+    public V put(final K key, final V value) {
         return cache.put(key, value);
     }
 
-    public Object get(final Object key) {
+    public V get(final K key) {
         return cache.get(key);
     }
 
@@ -53,9 +54,9 @@ public final class LRUCache implements MemoizeCache<Object, 
Object> {
      */
     public void cleanUpNullReferences() {
         synchronized (cache) {
-            final Iterator<Map.Entry<Object, Object>> iterator = 
cache.entrySet().iterator();
+            final Iterator<Map.Entry<K, V>> iterator = 
cache.entrySet().iterator();
             while (iterator.hasNext()) {
-                final Map.Entry<Object, Object> entry = iterator.next();
+                final Map.Entry<K, V> entry = iterator.next();
                 final Object value = entry.getValue();
 
                 if (!(value instanceof SoftReference)) continue;

Reply via email to