From 5cd7bdbbda0fa9f1aa6e12d9171c3811b73feb07 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 09 Jul 2015 14:01:31 +0000
Subject: [PATCH] Code cleanup

---
 opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerImpl.java |   34 ++++++++++++----------------------
 1 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerImpl.java b/opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerImpl.java
index 55ca6aa..2318dbb 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerImpl.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerImpl.java
@@ -73,7 +73,6 @@
 import org.opends.server.protocols.internal.InternalClientConnection;
 import org.opends.server.protocols.internal.InternalSearchOperation;
 import org.opends.server.protocols.internal.SearchRequest;
-import static org.opends.server.protocols.internal.Requests.*;
 import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
 import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
 import org.opends.server.protocols.ldap.LDAPMessage;
@@ -91,6 +90,8 @@
 import static org.opends.messages.CoreMessages.*;
 import static org.opends.server.config.ConfigConstants.*;
 import static org.opends.server.protocols.internal.InternalClientConnection.*;
+import static org.opends.server.protocols.internal.Requests.*;
+import static org.opends.server.util.CollectionUtils.*;
 import static org.opends.server.util.ServerConstants.*;
 import static org.opends.server.util.StaticUtils.*;
 
@@ -1101,14 +1102,11 @@
       // Write the value to the entry.
       InternalClientConnection internalConnection =
               InternalClientConnection.getRootConnection();
-      List<Modification> modifications = new ArrayList<>(1);
       Attribute attribute = Attributes.create(
           ConfigConstants.ATTR_CRYPTO_SYMMETRIC_KEY, symmetricKey);
-      modifications.add(
+      List<Modification> modifications = newArrayList(
           new Modification(ModificationType.ADD, attribute, false));
-      ModifyOperation internalModify =
-              internalConnection.processModify(entry.getName(),
-                      modifications);
+      ModifyOperation internalModify = internalConnection.processModify(entry.getName(), modifications);
       if (internalModify.getResultCode() != ResultCode.SUCCESS)
       {
         throw new CryptoManagerException(
@@ -1193,9 +1191,9 @@
                                       isCompromised);
 
         // Write the value to the entry.
-        List<Modification> modifications = new ArrayList<>(1);
         Attribute attribute = Attributes.create(ATTR_CRYPTO_SYMMETRIC_KEY, symmetricKey);
-        modifications.add(new Modification(ModificationType.ADD, attribute, false));
+        List<Modification> modifications = newArrayList(
+            new Modification(ModificationType.ADD, attribute, false));
         ModifyOperation internalModify =
              getRootConnection().processModify(entry.getName(), modifications);
         if (internalModify.getResultCode() != ResultCode.SUCCESS)
@@ -1522,17 +1520,9 @@
   }
 
   private static void putSingleValueAttribute(
-      Map<AttributeType, List<Attribute>> attrs, AttributeType type,
-      String value)
+      Map<AttributeType, List<Attribute>> attrs, AttributeType type, String value)
   {
-    attrs.put(type, asList(Attributes.create(type, value)));
-  }
-
-  private static <T> List<T> asList(T element)
-  {
-    ArrayList<T> attrList = new ArrayList<>(1);
-    attrList.add(element);
-    return attrList;
+    attrs.put(type, Attributes.createAsList(type, value));
   }
 
   /**
@@ -1625,7 +1615,7 @@
       LinkedHashMap<AttributeType,List<Attribute>> userAttrs = new LinkedHashMap<>();
 
       // Add the key ID attribute.
-      userAttrs.put(attrKeyID, asList(Attributes.create(attrKeyID, distinguishedValue)));
+      userAttrs.put(attrKeyID, Attributes.createAsList(attrKeyID, distinguishedValue));
 
       // Add the transformation name attribute.
       putSingleValueAttribute(userAttrs, attrTransformation, keyEntry.getType());
@@ -1658,7 +1648,7 @@
 
         builder.add(symmetricKey);
       }
-      userAttrs.put(attrSymmetricKey, asList(builder.toAttribute()));
+      userAttrs.put(attrSymmetricKey, builder.toAttributeList());
 
       // Create the entry.
       Entry entry = new Entry(entryDN, ocMap, userAttrs, opAttrs);
@@ -2146,7 +2136,7 @@
       LinkedHashMap<AttributeType,List<Attribute>> userAttrs = new LinkedHashMap<>();
 
       // Add the key ID attribute.
-      userAttrs.put(attrKeyID, asList(Attributes.create(attrKeyID, distinguishedValue)));
+      userAttrs.put(attrKeyID, Attributes.createAsList(attrKeyID, distinguishedValue));
 
       // Add the mac algorithm name attribute.
       putSingleValueAttribute(userAttrs, attrMacAlgorithm, keyEntry.getType());
@@ -2176,7 +2166,7 @@
         builder.add(symmetricKey);
       }
 
-      userAttrs.put(attrSymmetricKey, asList(builder.toAttribute()));
+      userAttrs.put(attrSymmetricKey, builder.toAttributeList());
 
       // Create the entry.
       Entry entry = new Entry(entryDN, ocMap, userAttrs, opAttrs);

--
Gitblit v1.10.0