You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/11/20 21:16:17 UTC

[commons-jcs] branch master updated: Initialize a collection when you create it.

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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git


The following commit(s) were added to refs/heads/master by this push:
     new cb40b71  Initialize a collection when you create it.
cb40b71 is described below

commit cb40b71df3c55a60fc0d60d726f77f95c812e7c7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 20 16:16:12 2020 -0500

    Initialize a collection when you create it.
---
 .../org/apache/commons/jcs3/engine/control/CompositeCache.java     | 3 +--
 .../apache/commons/jcs3/utils/discovery/UDPDiscoveryService.java   | 7 ++-----
 .../java/org/apache/commons/jcs3/jcache/cdi/CDIJCacheHelper.java   | 4 +---
 3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java
index 8dd1e26..2f52ba0 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java
@@ -982,9 +982,8 @@ public class CompositeCache<K, V>
      */
     public Set<K> getKeySet(boolean localOnly)
     {
-        HashSet<K> allKeys = new HashSet<>();
+        HashSet<K> allKeys = new HashSet<>(memCache.getKeySet());
 
-        allKeys.addAll(memCache.getKeySet());
         for (AuxiliaryCache<K, V> aux : auxCaches)
         {
             if (aux != null)
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryService.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryService.java
index 534ef1f..ddda523 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryService.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/discovery/UDPDiscoveryService.java
@@ -258,8 +258,7 @@ public class UDPDiscoveryService
      */
     protected ArrayList<String> getCacheNames()
     {
-        ArrayList<String> names = new ArrayList<>();
-        names.addAll( cacheNames );
+        ArrayList<String> names = new ArrayList<>(cacheNames);
         return names;
     }
 
@@ -343,9 +342,7 @@ public class UDPDiscoveryService
      */
     public Set<IDiscoveryListener> getCopyOfDiscoveryListeners()
     {
-        Set<IDiscoveryListener> copy = new HashSet<>();
-        copy.addAll( getDiscoveryListeners() );
-        return copy;
+        return new HashSet<>(getDiscoveryListeners());
     }
 
     /**
diff --git a/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/cdi/CDIJCacheHelper.java b/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/cdi/CDIJCacheHelper.java
index 6a5eab8..7454c38 100644
--- a/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/cdi/CDIJCacheHelper.java
+++ b/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/cdi/CDIJCacheHelper.java
@@ -129,9 +129,7 @@ public class CDIJCacheHelper
             annotations.add(set);
         }
 
-        final Set<Annotation> mtdAnnotations = new HashSet<>();
-        mtdAnnotations.addAll(Arrays.asList(ic.getMethod().getAnnotations()));
-
+        final Set<Annotation> mtdAnnotations = new HashSet<>(Arrays.asList(ic.getMethod().getAnnotations()));
         final CacheResult cacheResult = ic.getMethod().getAnnotation(CacheResult.class);
         final String cacheResultCacheResultName = cacheResult == null ? null : defaultName(ic.getMethod(), defaults, cacheResult.cacheName());
         final CacheResolverFactory cacheResultCacheResolverFactory = cacheResult == null ?