This is an automated email from the ASF dual-hosted git repository.

gk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/turbine-fulcrum-cache.git

commit b5fc03c1261032cd4201e067fe8837e18d43a704
Author: Georg Kallidis <[email protected]>
AuthorDate: Tue Dec 14 12:06:38 2021 +0100

    Update:  Use Java 8 streams and Method refs, update .gitignore
---
 .gitignore                                            |  4 ++--
 .../org/apache/fulcrum/cache/impl/EHCacheService.java | 19 ++++++++-----------
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/.gitignore b/.gitignore
index f84b100..0f49c04 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
-target
 *.log
-junit*.properties
+target/
+.settings/
 *.ser
 .classpath
 .project
diff --git a/src/java/org/apache/fulcrum/cache/impl/EHCacheService.java 
b/src/java/org/apache/fulcrum/cache/impl/EHCacheService.java
index 6be51bf..7273e24 100644
--- a/src/java/org/apache/fulcrum/cache/impl/EHCacheService.java
+++ b/src/java/org/apache/fulcrum/cache/impl/EHCacheService.java
@@ -22,6 +22,8 @@ package org.apache.fulcrum.cache.impl;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.activity.Initializable;
@@ -189,17 +191,12 @@ public class EHCacheService extends AbstractLogEnabled 
implements
     @Override
     public List<CachedObject<?>> getCachedObjects()
     {
-        ArrayList<CachedObject<?>> values = new ArrayList<CachedObject<?>>();
-
-        for (String key : getKeys())
-        {
-            Element cachedElement = this.cache.get(key);
-
-            if (cachedElement != null)
-            {
-                values.add((CachedObject<?>)cachedElement.getObjectValue());
-            }
-        }
+        ArrayList<CachedObject<?>> values =
+                getKeys().stream()
+                        .map(key -> this.cache.get(key))
+                        .filter(Objects::nonNull)
+                        .map(cachedElement -> (CachedObject<?>) 
cachedElement.getObjectValue())
+                        .collect(Collectors.toCollection(ArrayList::new));
 
         return values;
     }

Reply via email to