From c0e3c08676c0ebb9e822d466b48e49840945dcf4 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 28 Apr 2016 07:50:01 +0000
Subject: [PATCH] code cleanup

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java |   39 +++++++++++++++++++++------------------
 1 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java
index 775821f..40d33ae 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java
@@ -100,10 +100,11 @@
   @Override
   public boolean canLaunch(Task taskToBeLaunched, Collection<LocalizableMessage> incompatibilityReasons)
   {
+    Type taskTypeToBeLaunched = taskToBeLaunched.getType();
     if (state == State.RUNNING &&
-        (taskToBeLaunched.getType() == Task.Type.DELETE_SCHEMA_ELEMENT ||
-         taskToBeLaunched.getType() == Task.Type.MODIFY_SCHEMA_ELEMENT ||
-         taskToBeLaunched.getType() == Task.Type.NEW_SCHEMA_ELEMENT))
+        (taskTypeToBeLaunched == Task.Type.DELETE_SCHEMA_ELEMENT
+            || taskTypeToBeLaunched == Task.Type.MODIFY_SCHEMA_ELEMENT
+            || taskTypeToBeLaunched == Task.Type.NEW_SCHEMA_ELEMENT))
     {
       incompatibilityReasons.add(getIncompatibilityMessage(this, taskToBeLaunched));
       return false;
@@ -150,18 +151,19 @@
     {
       final List<String> attrNames = getElementsNameOrOID(attributeTypesToSchemaElements(attrsToAdd));
       final List<String> ocNames = getElementsNameOrOID(objectClassesToSchemaElements(ocsToAdd));
+      String attrNamesStr = joinAsString(", ", attrNames);
+      String ocNamesStr = joinAsString(", ", ocNames);
       if (ocNames.isEmpty())
       {
-        return INFO_CTRL_PANEL_NEW_ATTRIBUTES_TASK_DESCRIPTION.get(joinAsString(", ", attrNames));
+        return INFO_CTRL_PANEL_NEW_ATTRIBUTES_TASK_DESCRIPTION.get(attrNamesStr);
       }
       else if (attrNames.isEmpty())
       {
-        return INFO_CTRL_PANEL_NEW_OBJECTCLASSES_TASK_DESCRIPTION.get(joinAsString(", ", ocNames));
+        return INFO_CTRL_PANEL_NEW_OBJECTCLASSES_TASK_DESCRIPTION.get(ocNamesStr);
       }
       else
       {
-        return INFO_CTRL_PANEL_NEW_SCHEMA_ELEMENTS_TASK_DESCRIPTION.get(
-            joinAsString(", ", attrNames), joinAsString(", ", ocNames));
+        return INFO_CTRL_PANEL_NEW_SCHEMA_ELEMENTS_TASK_DESCRIPTION.get(attrNamesStr, ocNamesStr);
       }
     }
   }
@@ -430,12 +432,13 @@
   {
     if (!schemaElements.isEmpty())
     {
-      final Iterator<SomeSchemaElement> iterator = schemaElements.iterator();
-      final String firstOID = iterator.next().getOID();
-      buffer.append(" ").append(label).append(" ( ").append(firstOID);
-      while (iterator.hasNext())
+      buffer.append(" ").append(label).append(" ( ");
+
+      final Iterator<SomeSchemaElement> it = schemaElements.iterator();
+      buffer.append(it.next().getOID());
+      while (it.hasNext())
       {
-        buffer.append(" $ ").append(iterator.next().getOID());
+        buffer.append(" $ ").append(it.next().getOID());
       }
       buffer.append(" )");
     }
@@ -523,16 +526,16 @@
 
   private void appendCollection(final StringBuilder buffer, final String property, final Collection<String> values)
   {
-    final Iterator<String> iterator = values.iterator();
     final boolean isMultiValued = values.size() > 1;
-    if (iterator.hasNext())
+    if (!values.isEmpty())
     {
-      final String first = iterator.next();
       buffer.append(" ").append(property);
-      buffer.append(isMultiValued ? " ( '" : " '").append(first).append("' ");
-      while (iterator.hasNext())
+      buffer.append(isMultiValued ? " ( '" : " '");
+      final Iterator<String> it = values.iterator();
+      buffer.append(it.next()).append("' ");
+      while (it.hasNext())
       {
-        buffer.append("'").append(iterator.next()).append("' ");
+        buffer.append("'").append(it.next()).append("' ");
       }
       if (isMultiValued)
       {

--
Gitblit v1.10.0