Author: tv
Date: Sat Dec  8 18:06:47 2018
New Revision: 1848481

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

Modified:
    
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
    
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodCacheKey.java
    
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java

Modified: 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java?rev=1848481&r1=1848480&r2=1848481&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
 (original)
+++ 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/AbstractBaseManager.java
 Sat Dec  8 18:06:47 2018
@@ -31,6 +31,7 @@ import java.util.concurrent.ConcurrentHa
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.stream.Collectors;
 
 import org.apache.commons.jcs.JCS;
 import org.apache.commons.jcs.access.CacheAccess;
@@ -411,30 +412,23 @@ implements Serializable
             final boolean fromCache)
                     throws TorqueException
     {
-        List<T> oms = new ArrayList<>();
         if (ids != null && ids.size() > 0)
         {
             // start a new list where we will replace the id's with om's
             Map<ObjectKey, T> omsMap = new HashMap<>();
-            List<ObjectKey> newIds = new ArrayList<>(ids.size());
-            ids.forEach(key ->
+            List<ObjectKey> newIds = new ArrayList<>(ids);
+
+            if (fromCache)
             {
-                T om = null;
-                if (fromCache)
-                {
-                    om = cacheGet(key);
-                }
-                if (om == null)
-                {
-                    newIds.add(key);
-                }
-                else
-                {
-                    omsMap.put(key, om);
-                }
-            });
+                ids.stream()
+                    .map(key -> cacheGet(key))
+                    .filter(om -> om != null)
+                    .forEach(om -> omsMap.put(om.getPrimaryKey(), om));
 
-            if (newIds.size() > 0)
+                newIds.removeAll(omsMap.keySet());
+            }
+
+            if (!newIds.isEmpty())
             {
                 List<T> newOms = retrieveStoredOMs(newIds);
                 for (T om : newOms)
@@ -447,9 +441,12 @@ implements Serializable
                 }
             }
 
-            ids.forEach(key -> oms.add(omsMap.get(key)));
+            return ids.stream()
+                    .map(key -> omsMap.get(key))
+                    .collect(Collectors.toList());
         }
-        return oms;
+
+        return new ArrayList<>();
     }
 
     /**

Modified: 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodCacheKey.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodCacheKey.java?rev=1848481&r1=1848480&r2=1848481&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodCacheKey.java
 (original)
+++ 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/manager/MethodCacheKey.java
 Sat Dec  8 18:06:47 2018
@@ -20,6 +20,8 @@ package org.apache.torque.manager;
  */
 
 import java.io.Serializable;
+import java.util.Arrays;
+import java.util.stream.Collectors;
 
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
@@ -133,18 +135,14 @@ public class MethodCacheKey implements S
     public String toString()
     {
         StringBuilder sb = new StringBuilder();
-        sb.append(instanceOrClass);
-        sb.append("::");
-        sb.append(method).append('(');
-        for (int i = 0; i < args.length; i++)
-        {
-            sb.append(args[i]);
-            if (i < args.length - 1)
-            {
-                sb.append(", ");
-            }
-        }
-        sb.append(')');
+        sb.append(instanceOrClass)
+            .append("::")
+            .append(method)
+            .append('(')
+            .append(Arrays.stream(args)
+                    .map(arg -> arg.toString())
+                    .collect(Collectors.joining(", ")))
+            .append(')');
         return sb.toString();
     }
 }

Modified: 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java?rev=1848481&r1=1848480&r2=1848481&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java
 (original)
+++ 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java
 Sat Dec  8 18:06:47 2018
@@ -26,6 +26,7 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.StringTokenizer;
+import java.util.stream.Collectors;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.torque.Database;
@@ -388,18 +389,11 @@ public class DatabaseMap extends OptionS
         StringBuilder result = new StringBuilder();
         result.append("DatabaseMap[name=")
         .append(name)
-        .append(", tables=(");
-        boolean first = true;
-        for (TableMap table : tables.values())
-        {
-            if (!first)
-            {
-                result.append(',');
-            }
-            result.append(table.getName());
-            first = false;
-        }
-        result.append(")]");
+        .append(", tables=(")
+        .append(tables.values().stream()
+                .map(table -> table.getName())
+                .collect(Collectors.joining(",")))
+        .append(")]");
         return result.toString();
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscr...@db.apache.org
For additional commands, e-mail: torque-dev-h...@db.apache.org

Reply via email to