Author: tv
Date: Mon Dec 10 21:02:58 2018
New Revision: 1848637

URL: http://svn.apache.org/viewvc?rev=1848637&view=rev
Log:
Use streaming where appropriate

Modified:
    
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/AbstractAuxiliaryCache.java
    
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/AbstractMemoryCache.java

Modified: 
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/AbstractAuxiliaryCache.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/AbstractAuxiliaryCache.java?rev=1848637&r1=1848636&r2=1848637&view=diff
==============================================================================
--- 
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/AbstractAuxiliaryCache.java
 (original)
+++ 
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/AbstractAuxiliaryCache.java
 Mon Dec 10 21:02:58 2018
@@ -56,9 +56,9 @@ public abstract class AbstractAuxiliaryC
      */
     protected Map<K, ICacheElement<K, V>> processGetMultiple(Set<K> keys) 
throws IOException
     {
-        if ( keys != null && !keys.isEmpty() )
+        if (keys != null)
         {
-            Map<K, ICacheElement<K, V>> elements = keys.stream()
+            return keys.stream()
                 .map(key -> {
                     try
                     {
@@ -73,8 +73,6 @@ public abstract class AbstractAuxiliaryC
                 .collect(Collectors.toMap(
                         element -> element.getKey(),
                         element -> element));
-
-            return elements;
         }
 
         return new HashMap<K, ICacheElement<K, V>>();

Modified: 
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/AbstractMemoryCache.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/AbstractMemoryCache.java?rev=1848637&r1=1848636&r2=1848637&view=diff
==============================================================================
--- 
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/AbstractMemoryCache.java
 (original)
+++ 
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/memory/AbstractMemoryCache.java
 Mon Dec 10 21:02:58 2018
@@ -29,6 +29,7 @@ import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
+import java.util.stream.Collectors;
 
 import org.apache.commons.jcs.engine.CacheConstants;
 import org.apache.commons.jcs.engine.behavior.ICacheElement;
@@ -115,22 +116,26 @@ public abstract class AbstractMemoryCach
     public Map<K, ICacheElement<K, V>> getMultiple( Set<K> keys )
         throws IOException
     {
-        Map<K, ICacheElement<K, V>> elements = new HashMap<K, ICacheElement<K, 
V>>();
-
-        if ( keys != null && !keys.isEmpty() )
+        if (keys != null)
         {
-            for (K key : keys)
-            {
-                ICacheElement<K, V> element = get( key );
-
-                if ( element != null )
-                {
-                    elements.put( key, element );
-                }
-            }
+            return keys.stream()
+                .map(key -> {
+                    try
+                    {
+                        return get(key);
+                    }
+                    catch (IOException e)
+                    {
+                        return null;
+                    }
+                })
+                .filter(element -> element != null)
+                .collect(Collectors.toMap(
+                        element -> element.getKey(),
+                        element -> element));
         }
 
-        return elements;
+        return new HashMap<K, ICacheElement<K, V>>();
     }
 
     /**


Reply via email to