From cdbc97a66ca18d9f74b58c3fbca253f17d4dcd55 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 02 Feb 2016 10:57:43 +0000
Subject: [PATCH] Code cleanups: - remove isEmpty() checks when lists are iterated immediately after - extracted methods - removed {@inheritDoc} javadocs

---
 opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerSync.java |   27 ++++++++++++++-------------
 1 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerSync.java b/opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerSync.java
index 551bf4f..e651a33 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerSync.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerSync.java
@@ -35,6 +35,7 @@
 import static org.opends.server.util.ServerConstants.*;
 import static org.opends.server.util.StaticUtils.*;
 
+import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -45,6 +46,7 @@
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.forgerock.opendj.ldap.ResultCode;
 import org.forgerock.opendj.ldap.SearchScope;
+import org.forgerock.opendj.ldap.schema.AttributeType;
 import org.opends.admin.ads.ADSContext;
 import org.opends.server.api.Backend;
 import org.opends.server.api.BackendInitializationListener;
@@ -60,7 +62,6 @@
 import org.opends.server.protocols.internal.SearchRequest;
 import org.opends.server.protocols.ldap.LDAPControl;
 import org.opends.server.types.Attribute;
-import org.forgerock.opendj.ldap.schema.AttributeType;
 import org.opends.server.types.Control;
 import org.opends.server.types.CryptoManagerException;
 import org.opends.server.types.DN;
@@ -399,18 +400,8 @@
     ocMap.put(ocInstanceKey, OC_CRYPTO_INSTANCE_KEY);
 
     Map<AttributeType, List<Attribute>> userAttrs = new HashMap<>();
-
-    List<Attribute> attrList;
-    attrList = srcEntry.getAttribute(attrAlias);
-    if (!attrList.isEmpty())
-    {
-      userAttrs.put(attrAlias, attrList);
-    }
-    attrList = srcEntry.getAttribute(attrCert);
-    if (!attrList.isEmpty())
-    {
-      userAttrs.put(attrCert, attrList);
-    }
+    putAttributeTypeIfExist(userAttrs, srcEntry, attrAlias);
+    putAttributeTypeIfExist(userAttrs, srcEntry, attrCert);
 
     Entry addEntry = new Entry(dstDN, ocMap, userAttrs, null);
     AddOperation addOperation = getRootConnection().processAdd(addEntry);
@@ -420,6 +411,16 @@
     }
   }
 
+  private void putAttributeTypeIfExist(Map<AttributeType, List<Attribute>> userAttrs, Entry srcEntry,
+      AttributeType attrType)
+  {
+    List<Attribute> attrList = srcEntry.getAttribute(attrType);
+    if (!attrList.isEmpty())
+    {
+      userAttrs.put(attrType, new ArrayList<>(attrList));
+    }
+  }
+
   @Override
   public PostResponse doPostResponse(PostResponseAddOperation op)
   {

--
Gitblit v1.10.0