From 6b47d8afcb80c74e8c29d2702a38e8948056b462 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 27 Jan 2015 15:20:15 +0000
Subject: [PATCH] Code cleanup: Used Sets instead of Lists where it makes sense.

---
 opendj3-server-dev/src/server/org/opends/server/tasks/ImportTask.java |   78 ++++++++++-----------------------------
 1 files changed, 20 insertions(+), 58 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/tasks/ImportTask.java b/opendj3-server-dev/src/server/org/opends/server/tasks/ImportTask.java
index 85fc865..71bfbec 100644
--- a/opendj3-server-dev/src/server/org/opends/server/tasks/ImportTask.java
+++ b/opendj3-server-dev/src/server/org/opends/server/tasks/ImportTask.java
@@ -239,10 +239,8 @@
 
     Backend<?> backend = null;
     ArrayList<DN> defaultIncludeBranches;
-    ArrayList<DN> excludeBranches =
-        new ArrayList<DN>(excludeBranchStrings.size());
-    ArrayList<DN> includeBranches =
-        new ArrayList<DN>(includeBranchStrings.size());
+    HashSet<DN> excludeBranches = new HashSet<DN>(excludeBranchStrings.size());
+    HashSet<DN> includeBranches = new HashSet<DN>(includeBranchStrings.size());
 
     for (String s : includeBranchStrings)
     {
@@ -264,10 +262,7 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
       }
 
-      if(! includeBranches.contains(includeBranch))
-      {
-        includeBranches.add(includeBranch);
-      }
+      includeBranches.add(includeBranch);
     }
     for (String s : excludeBranchStrings)
     {
@@ -289,10 +284,7 @@
         throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message);
       }
 
-      if (! excludeBranches.contains(excludeBranch))
-      {
-        excludeBranches.add(excludeBranch);
-      }
+      excludeBranches.add(excludeBranch);
     }
 
     for (String filterString : excludeFilterStrings)
@@ -487,11 +479,9 @@
 
     // Get the backend into which the LDIF should be imported.
     Backend<?> backend = null;
-    ArrayList<DN> defaultIncludeBranches;
-    ArrayList<DN> excludeBranches =
-        new ArrayList<DN>(excludeBranchStrings.size());
-    ArrayList<DN> includeBranches =
-        new ArrayList<DN>(includeBranchStrings.size());
+    HashSet<DN> defaultIncludeBranches;
+    HashSet<DN> excludeBranches = new HashSet<DN>(excludeBranchStrings.size());
+    HashSet<DN> includeBranches = new HashSet<DN>(includeBranchStrings.size());
 
     for (String s : includeBranchStrings)
     {
@@ -511,10 +501,7 @@
         return TaskState.STOPPED_BY_ERROR;
       }
 
-      if(! includeBranches.contains(includeBranch))
-      {
-        includeBranches.add(includeBranch);
-      }
+      includeBranches.add(includeBranch);
     }
 
     if(backendID != null)
@@ -574,7 +561,7 @@
     // Find backends with subordinate base DNs that should be excluded from the
     // import.
 
-    defaultIncludeBranches = new ArrayList<DN>(backend.getBaseDNs().length);
+    defaultIncludeBranches = new HashSet<DN>(backend.getBaseDNs().length);
     for (DN dn : backend.getBaseDNs())
     {
       defaultIncludeBranches.add(dn);
@@ -588,14 +575,9 @@
         {
           for (DN importBase : defaultIncludeBranches)
           {
-            if (baseDN.isDescendantOf(importBase)
-                && !baseDN.equals(importBase))
+            if (!baseDN.equals(importBase) && baseDN.isDescendantOf(importBase))
             {
-              if (! excludeBranches.contains(baseDN))
-              {
-                excludeBranches.add(baseDN);
-              }
-
+              excludeBranches.add(baseDN);
               break;
             }
           }
@@ -621,10 +603,7 @@
         return TaskState.STOPPED_BY_ERROR;
       }
 
-      if (! excludeBranches.contains(excludeBranch))
-      {
-        excludeBranches.add(excludeBranch);
-      }
+      excludeBranches.add(excludeBranch);
     }
 
     if (includeBranchStrings.isEmpty())
@@ -707,15 +686,8 @@
     {
       try
       {
-        ExistingFileBehavior existingBehavior;
-        if (overwrite)
-        {
-          existingBehavior = ExistingFileBehavior.OVERWRITE;
-        }
-        else
-        {
-          existingBehavior = ExistingFileBehavior.APPEND;
-        }
+        ExistingFileBehavior existingBehavior =
+            overwrite ? ExistingFileBehavior.OVERWRITE : ExistingFileBehavior.APPEND;
 
         importConfig.writeRejectedEntries(rejectFile, existingBehavior);
       }
@@ -730,15 +702,8 @@
     {
       try
       {
-        ExistingFileBehavior existingBehavior;
-        if (overwrite)
-        {
-          existingBehavior = ExistingFileBehavior.OVERWRITE;
-        }
-        else
-        {
-          existingBehavior = ExistingFileBehavior.APPEND;
-        }
+        ExistingFileBehavior existingBehavior =
+            overwrite ? ExistingFileBehavior.OVERWRITE : ExistingFileBehavior.APPEND;
         importConfig.writeSkippedEntries(skipFile, existingBehavior);
       }
       catch (Exception e)
@@ -804,19 +769,16 @@
         logger.traceException(de);
 
         DirectoryServer.notifyImportEnded(backend, importConfig, false);
-        LocalizableMessage message = null;
+        LocalizableMessage msg;
         if (de.getResultCode() == ResultCode.CONSTRAINT_VIOLATION)
         {
-          message =
-              ERR_LDIFIMPORT_ERROR_DURING_IMPORT
-                  .get(ERR_LDIFIMPORT_ERROR_CONSTRAINT_VIOLATION.get());
+          msg = ERR_LDIFIMPORT_ERROR_CONSTRAINT_VIOLATION.get();
         }
         else
         {
-          message = ERR_LDIFIMPORT_ERROR_DURING_IMPORT.get(
-              de.getMessageObject());
+          msg = de.getMessageObject();
         }
-        logger.error(message);
+        logger.error(ERR_LDIFIMPORT_ERROR_DURING_IMPORT.get(msg));
         return TaskState.STOPPED_BY_ERROR;
       }
       catch (Exception e)

--
Gitblit v1.10.0