From 6b41484b811fdb343e6dcccb8dddfa223800a138 Mon Sep 17 00:00:00 2001
From: Yannick Lecaillez <yannick.lecaillez@forgerock.com>
Date: Tue, 19 May 2015 13:32:55 +0000
Subject: [PATCH] Minor cleanup (use diamond & interface)

---
 opendj-server-legacy/src/main/java/org/opends/server/extensions/FIFOEntryCache.java |   63 +++++++++++++++----------------
 1 files changed, 30 insertions(+), 33 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/extensions/FIFOEntryCache.java b/opendj-server-legacy/src/main/java/org/opends/server/extensions/FIFOEntryCache.java
index 93e6400..54c1a96 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/extensions/FIFOEntryCache.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/extensions/FIFOEntryCache.java
@@ -31,6 +31,7 @@
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.forgerock.i18n.LocalizableMessage;
@@ -90,7 +91,7 @@
   private static final Runtime runtime = Runtime.getRuntime();
 
   /** The mapping between entry backends/IDs and entries. */
-  private HashMap<Backend<?>, HashMap<Long, CacheEntry>> idMap;
+  private Map<Backend<?>, Map<Long, CacheEntry>> idMap;
 
   /** The mapping between DNs and entries. */
   private LinkedHashMap<DN,CacheEntry> dnMap;
@@ -99,7 +100,7 @@
    * The lock used to provide threadsafe access when changing the contents of
    * the cache.
    */
-  private ReentrantReadWriteLock cacheLock;
+  private ReadWriteLock cacheLock;
   private Lock cacheWriteLock;
   private Lock cacheReadLock;
 
@@ -134,8 +135,8 @@
     configuration.addFIFOChangeListener (this);
 
     // Initialize the cache structures.
-    idMap     = new HashMap<Backend<?>, HashMap<Long, CacheEntry>>();
-    dnMap     = new LinkedHashMap<DN,CacheEntry>();
+    idMap = new HashMap<>();
+    dnMap = new LinkedHashMap<>();
 
     // Initialize locks.
     cacheLock = new ReentrantReadWriteLock(true);
@@ -144,7 +145,7 @@
 
     // Read configuration and apply changes.
     boolean applyChanges = true;
-    ArrayList<LocalizableMessage> errorMessages = new ArrayList<LocalizableMessage>();
+    List<LocalizableMessage> errorMessages = new ArrayList<>();
     EntryCacheCommon.ConfigErrorHandler errorHandler =
       EntryCacheCommon.getConfigErrorHandler (
           EntryCacheCommon.ConfigPhase.PHASE_INIT, null, errorMessages
@@ -206,11 +207,10 @@
         // Indicate cache miss.
         cacheMisses.getAndIncrement();
         return null;
-      } else {
-        // Indicate cache hit.
-        cacheHits.getAndIncrement();
-        return e.getEntry();
       }
+      // Indicate cache hit.
+      cacheHits.getAndIncrement();
+      return e.getEntry();
     } finally {
       cacheReadLock.unlock();
     }
@@ -237,7 +237,7 @@
     // Locate specific backend map and return the entry DN by ID.
     cacheReadLock.lock();
     try {
-      HashMap<Long, CacheEntry> backendMap = idMap.get(backend);
+      Map<Long, CacheEntry> backendMap = idMap.get(backend);
       if (backendMap != null) {
         CacheEntry e = backendMap.get(entryID);
         if (e != null) {
@@ -295,7 +295,7 @@
             CacheEntry ce = iterator.next();
             iterator.remove();
 
-            HashMap<Long,CacheEntry> m = idMap.get(ce.getBackend());
+            Map<Long,CacheEntry> m = idMap.get(ce.getBackend());
             if (m != null)
             {
               m.remove(ce.getEntryID());
@@ -324,10 +324,10 @@
         // present and add it if it isn't.
         dnMap.put(entry.getName(), cacheEntry);
 
-        HashMap<Long,CacheEntry> map = idMap.get(backend);
+        Map<Long,CacheEntry> map = idMap.get(backend);
         if (map == null)
         {
-          map = new HashMap<Long,CacheEntry>();
+          map = new HashMap<>();
           map.put(entryID, cacheEntry);
           idMap.put(backend, map);
         }
@@ -349,7 +349,7 @@
             CacheEntry ce = iterator.next();
             iterator.remove();
 
-            HashMap<Long,CacheEntry> m = idMap.get(ce.getBackend());
+            Map<Long,CacheEntry> m = idMap.get(ce.getBackend());
             if (m != null)
             {
               m.remove(ce.getEntryID());
@@ -420,7 +420,7 @@
           CacheEntry ce = iterator.next();
           iterator.remove();
 
-          HashMap<Long,CacheEntry> m = idMap.get(ce.getBackend());
+          Map<Long,CacheEntry> m = idMap.get(ce.getBackend());
           if (m != null)
           {
             m.remove(ce.getEntryID());
@@ -433,10 +433,10 @@
         // present and add it if it isn't.
         dnMap.put(entry.getName(), cacheEntry);
 
-        HashMap<Long,CacheEntry> map = idMap.get(backend);
+        Map<Long,CacheEntry> map = idMap.get(backend);
         if (map == null)
         {
-          map = new HashMap<Long,CacheEntry>();
+          map = new HashMap<>();
           map.put(entryID, cacheEntry);
           idMap.put(backend, map);
         }
@@ -458,7 +458,7 @@
             CacheEntry ce = iterator.next();
             iterator.remove();
 
-            HashMap<Long,CacheEntry> m = idMap.get(ce.getBackend());
+            Map<Long,CacheEntry> m = idMap.get(ce.getBackend());
             if (m != null)
             {
               m.remove(ce.getEntryID());
@@ -587,7 +587,7 @@
     try
     {
       // Remove all references to entries for this backend from the ID cache.
-      HashMap<Long,CacheEntry> map = idMap.remove(backend);
+      Map<Long,CacheEntry> map = idMap.remove(backend);
       if (map == null)
       {
         // No entries were in the cache for this backend, so we can return
@@ -677,7 +677,7 @@
   {
     // See if there are any entries for the provided backend in the cache.  If
     // not, then return.
-    HashMap<Long,CacheEntry> map = idMap.get(backend);
+    Map<Long,CacheEntry> map = idMap.get(backend);
     if (map == null)
     {
       // No entries were in the cache for this backend, so we can return without
@@ -764,7 +764,7 @@
           CacheEntry entry = iterator.next();
           iterator.remove();
 
-          HashMap<Long,CacheEntry> m = idMap.get(entry.getBackend());
+          Map<Long,CacheEntry> m = idMap.get(entry.getBackend());
           if (m != null)
           {
             m.remove(entry.getEntryID());
@@ -819,7 +819,7 @@
   public ConfigChangeResult applyConfigurationChange(      FIFOEntryCacheCfg configuration      )
   {
     boolean applyChanges = true;
-    ArrayList<LocalizableMessage> errorMessages = new ArrayList<LocalizableMessage>();
+    List<LocalizableMessage> errorMessages = new ArrayList<>();
     EntryCacheCommon.ConfigErrorHandler errorHandler =
       EntryCacheCommon.getConfigErrorHandler (
           EntryCacheCommon.ConfigPhase.PHASE_APPLY, null, errorMessages
@@ -856,8 +856,8 @@
       )
   {
     // Local variables to read configuration.
-    HashSet<SearchFilter> newIncludeFilters = null;
-    HashSet<SearchFilter> newExcludeFilters = null;
+    Set<SearchFilter> newIncludeFilters = null;
+    Set<SearchFilter> newExcludeFilters = null;
 
     // Read configuration.
     DN newConfigEntryDN = configuration.dn();
@@ -905,12 +905,10 @@
 
   /** {@inheritDoc} */
   @Override
-  public ArrayList<Attribute> getMonitorData()
+  public List<Attribute> getMonitorData()
   {
-    ArrayList<Attribute> attrs = new ArrayList<Attribute>();
-
     try {
-      attrs = EntryCacheCommon.getGenericMonitorData(
+      return EntryCacheCommon.getGenericMonitorData(
         Long.valueOf(cacheHits.longValue()),
         // If cache misses is maintained by default cache
         // get it from there and if not point to itself.
@@ -923,9 +921,8 @@
         );
     } catch (Exception e) {
       logger.traceException(e);
+      return Collections.emptyList();
     }
-
-    return attrs;
   }
 
   /** {@inheritDoc} */
@@ -942,7 +939,7 @@
     StringBuilder sb = new StringBuilder();
 
     Map<DN,CacheEntry> dnMapCopy;
-    Map<Backend<?>, HashMap<Long, CacheEntry>> idMapCopy;
+    Map<Backend<?>, Map<Long, CacheEntry>> idMapCopy;
 
     // Grab cache lock to prevent any modifications
     // to the cache maps until a snapshot is taken.
@@ -951,8 +948,8 @@
       // Examining the real maps will hold the lock and can cause map
       // modifications in case of any access order maps, make copies
       // instead.
-      dnMapCopy = new LinkedHashMap<DN,CacheEntry>(dnMap);
-      idMapCopy = new HashMap<Backend<?>, HashMap<Long, CacheEntry>>(idMap);
+      dnMapCopy = new LinkedHashMap<>(dnMap);
+      idMapCopy = new HashMap<>(idMap);
     } finally {
       cacheWriteLock.unlock();
     }

--
Gitblit v1.10.0