From ce983e3c50103f5cca91c8ade7409d9d23d398d0 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 25 Aug 2015 15:59:10 +0000
Subject: [PATCH] CommonSchemaElements.java: Changed getNormalizedNames() to return a Set instead of Iterable.

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java    |    7 -
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java |   41 ++-------
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SchemaElementPanel.java         |   27 +-----
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyAttributeTask.java      |   77 +++++++-----------
 opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java                   |   60 --------------
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyObjectClassTask.java    |   16 +---
 6 files changed, 57 insertions(+), 171 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
index 9b2986a..04fa3ca 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
@@ -70,9 +70,7 @@
 import org.opends.server.util.LDIFWriter;
 import org.opends.server.util.StaticUtils;
 
-/**
- * The task that is launched when a schema element must be deleted.
- */
+/** The task that is launched when a schema element must be deleted. */
 public class DeleteSchemaElementsTask extends Task
 {
   /** The list of object classes that the user asked to delete. */
@@ -116,17 +114,15 @@
     }
     if (!ocsToDelete.isEmpty())
     {
+      LinkedHashSet<ObjectClass> orderedOCs =
+          DeleteSchemaElementsTask.getOrderedObjectClassesToDelete(ocsToDelete, schema);
       if (allOcsToDelete == null)
       {
-      allOcsToDelete =
-        DeleteSchemaElementsTask.getOrderedObjectClassesToDelete(
-            ocsToDelete, schema);
+        allOcsToDelete = orderedOCs;
       }
       else
       {
-        allOcsToDelete.addAll(
-            DeleteSchemaElementsTask.getOrderedObjectClassesToDelete(
-                ocsToDelete, schema));
+        allOcsToDelete.addAll(orderedOCs);
       }
     }
     ArrayList<AttributeType> lAttrsToDelete = new ArrayList<>(allAttrsToDelete);
@@ -541,7 +537,6 @@
 
   private AttributeType getAttributeToAdd(AttributeType attrToDelete)
   {
-    AttributeType attrToAdd;
     boolean isSuperior = false;
     for (AttributeType attr : providedAttrsToDelete)
     {
@@ -559,14 +554,10 @@
     }
     if (isSuperior)
     {
-      ArrayList<String> allNames = new ArrayList<>();
-      for (String str : attrToDelete.getNormalizedNames())
-      {
-        allNames.add(str);
-      }
+      ArrayList<String> allNames = new ArrayList<>(attrToDelete.getNormalizedNames());
       Map<String, List<String>> extraProperties =
         cloneExtraProperties(attrToDelete);
-      attrToAdd = new AttributeType(
+      return new AttributeType(
           "",
           attrToDelete.getPrimaryName(),
           allNames,
@@ -588,14 +579,12 @@
     else
     {
       // Nothing to be changed in the definition of the attribute itself.
-      attrToAdd = attrToDelete;
+      return attrToDelete;
     }
-    return attrToAdd;
   }
 
   private ObjectClass getObjectClassToAdd(ObjectClass ocToDelete)
   {
-    ObjectClass ocToAdd;
     boolean containsAttribute = false;
     for (AttributeType attr : providedAttrsToDelete)
     {
@@ -630,11 +619,7 @@
 
     if (containsAttribute || hasSuperior)
     {
-      ArrayList<String> allNames = new ArrayList<>();
-      for (String str : ocToDelete.getNormalizedNames())
-      {
-        allNames.add(str);
-      }
+      ArrayList<String> allNames = new ArrayList<>(ocToDelete.getNormalizedNames());
       Map<String, List<String>> extraProperties =
         cloneExtraProperties(ocToDelete);
       Set<AttributeType> required;
@@ -651,7 +636,7 @@
         required = ocToDelete.getRequiredAttributes();
         optional = ocToDelete.getOptionalAttributes();
       }
-      ocToAdd = new ObjectClass("",
+      return new ObjectClass("",
           ocToDelete.getPrimaryName(),
           allNames,
           ocToDelete.getOID(),
@@ -666,12 +651,10 @@
     else
     {
       // Nothing to be changed in the definition of the object class itself.
-      ocToAdd = ocToDelete;
+      return ocToDelete;
     }
-    return ocToAdd;
   }
 
-
   private Set<ObjectClass> getNewSuperiors(ObjectClass currentSup)
   {
     Set<ObjectClass> newSuperiors = new LinkedHashSet<>();
@@ -693,7 +676,6 @@
     return newSuperiors;
   }
 
-
   /**
    * Returns an ordered set of the attributes that must be deleted.
    * @param attrsToDelete the attributes to be deleted.
@@ -785,7 +767,6 @@
     return extraProperties;
   }
 
-
   private static LinkedHashSet<AttributeType> getOrderedChildrenToDelete(
       AttributeType attribute, Schema schema)
   {
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyAttributeTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyAttributeTask.java
index 9a579e2..036afe6 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyAttributeTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyAttributeTask.java
@@ -149,64 +149,50 @@
 
   private AttributeType getAttributeToAdd(AttributeType attrToDelete)
   {
-    AttributeType attrToAdd;
     if (attrToDelete.equals(oldAttribute))
     {
-      attrToAdd = newAttribute;
+      return newAttribute;
+    }
+    else if (oldAttribute.equals(attrToDelete.getSuperiorType()))
+    {
+      ArrayList<String> allNames = new ArrayList<>(attrToDelete.getNormalizedNames());
+      Map<String, List<String>> extraProperties =
+        DeleteSchemaElementsTask.cloneExtraProperties(attrToDelete);
+      AttributeType newSuperior = newAttribute;
+      return new AttributeType(
+          "",
+          attrToDelete.getPrimaryName(),
+          allNames,
+          attrToDelete.getOID(),
+          attrToDelete.getDescription(),
+          newSuperior,
+          attrToDelete.getSyntax(),
+          attrToDelete.getApproximateMatchingRule(),
+          attrToDelete.getEqualityMatchingRule(),
+          attrToDelete.getOrderingMatchingRule(),
+          attrToDelete.getSubstringMatchingRule(),
+          attrToDelete.getUsage(),
+          attrToDelete.isCollective(),
+          attrToDelete.isNoUserModification(),
+          attrToDelete.isObsolete(),
+          attrToDelete.isSingleValue(),
+          extraProperties);
     }
     else
     {
-      if (oldAttribute.equals(attrToDelete.getSuperiorType()))
-      {
-        ArrayList<String> allNames = new ArrayList<>();
-        for (String str : attrToDelete.getNormalizedNames())
-        {
-          allNames.add(str);
-        }
-        Map<String, List<String>> extraProperties =
-          DeleteSchemaElementsTask.cloneExtraProperties(attrToDelete);
-        AttributeType newSuperior = newAttribute;
-        attrToAdd = new AttributeType(
-            "",
-            attrToDelete.getPrimaryName(),
-            allNames,
-            attrToDelete.getOID(),
-            attrToDelete.getDescription(),
-            newSuperior,
-            attrToDelete.getSyntax(),
-            attrToDelete.getApproximateMatchingRule(),
-            attrToDelete.getEqualityMatchingRule(),
-            attrToDelete.getOrderingMatchingRule(),
-            attrToDelete.getSubstringMatchingRule(),
-            attrToDelete.getUsage(),
-            attrToDelete.isCollective(),
-            attrToDelete.isNoUserModification(),
-            attrToDelete.isObsolete(),
-            attrToDelete.isSingleValue(),
-            extraProperties);
-      }
-      else
-      {
-        // Nothing to be changed in the definition of the attribute itself.
-        attrToAdd = attrToDelete;
-      }
+      // Nothing to be changed in the definition of the attribute itself.
+      return attrToDelete;
     }
-    return attrToAdd;
   }
 
   private ObjectClass getObjectClassToAdd(ObjectClass ocToDelete)
   {
-    ObjectClass ocToAdd;
     boolean containsAttribute =
       ocToDelete.getRequiredAttributeChain().contains(oldAttribute) ||
       ocToDelete.getOptionalAttributeChain().contains(oldAttribute);
     if (containsAttribute)
     {
-      ArrayList<String> allNames = new ArrayList<>();
-      for (String str : ocToDelete.getNormalizedNames())
-      {
-        allNames.add(str);
-      }
+      ArrayList<String> allNames = new ArrayList<>(ocToDelete.getNormalizedNames());
       Map<String, List<String>> extraProperties =
         DeleteSchemaElementsTask.cloneExtraProperties(ocToDelete);
       Set<AttributeType> required = new HashSet<>(ocToDelete.getRequiredAttributes());
@@ -221,7 +207,7 @@
         optional.remove(oldAttribute);
         optional.add(newAttribute);
       }
-      ocToAdd = new ObjectClass("",
+      return new ObjectClass("",
           ocToDelete.getPrimaryName(),
           allNames,
           ocToDelete.getOID(),
@@ -236,9 +222,8 @@
     else
     {
       // Nothing to be changed in the definition of the object class itself.
-      ocToAdd = ocToDelete;
+      return ocToDelete;
     }
-    return ocToAdd;
   }
 
   /**
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyObjectClassTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyObjectClassTask.java
index e1357a3..06acac1 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyObjectClassTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyObjectClassTask.java
@@ -52,7 +52,6 @@
 /**
  * The task that is in charge of modifying an object class definition (and all
  * the references to this object class).
- *
  */
 public class ModifyObjectClassTask extends Task
 {
@@ -147,22 +146,16 @@
     }
   }
 
-
   private ObjectClass getObjectClassToAdd(ObjectClass ocToDelete)
   {
-    ObjectClass ocToAdd;
     Set<ObjectClass> currentSups = ocToDelete.getSuperiorClasses();
     if (ocToDelete.equals(oldObjectClass))
     {
-      ocToAdd = newObjectClass;
+      return newObjectClass;
     }
     else if (currentSups.contains(oldObjectClass))
     {
-      ArrayList<String> allNames = new ArrayList<>();
-      for (String str : ocToDelete.getNormalizedNames())
-      {
-        allNames.add(str);
-      }
+      ArrayList<String> allNames = new ArrayList<>(ocToDelete.getNormalizedNames());
       Map<String, List<String>> extraProperties =
         DeleteSchemaElementsTask.cloneExtraProperties(ocToDelete);
       Set<ObjectClass> newSups = new LinkedHashSet<>();
@@ -177,7 +170,7 @@
           newSups.add(oc);
         }
       }
-      ocToAdd = new ObjectClass("",
+      return new ObjectClass("",
           ocToDelete.getPrimaryName(),
           allNames,
           ocToDelete.getOID(),
@@ -192,9 +185,8 @@
     else
     {
       // Nothing to be changed in the definition of the object class itself.
-      ocToAdd = ocToDelete;
+      return ocToDelete;
     }
-    return ocToAdd;
   }
 
   /**
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 8763d96..fc39f75 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
@@ -364,12 +364,7 @@
 
   private String getElementDefinition(CommonSchemaElements element)
   {
-    final List<String> names = new ArrayList<>();
-    for (final String name : element.getNormalizedNames())
-    {
-      names.add(name);
-    }
-
+    final List<String> names = new ArrayList<>(element.getNormalizedNames());
     if (element instanceof AttributeType)
     {
       return getAttributeTypeDefinition((AttributeType) element, names);
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SchemaElementPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SchemaElementPanel.java
index e4f7016..24fe1c9 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SchemaElementPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SchemaElementPanel.java
@@ -24,7 +24,6 @@
  *      Copyright 2008-2010 Sun Microsystems, Inc.
  *      Portions Copyright 2015 ForgeRock AS.
  */
-
 package org.opends.guitools.controlpanel.ui;
 
 import java.util.HashSet;
@@ -44,7 +43,6 @@
 /**
  * Abstract class used to re-factor some code among the panels that display the
  * contents of a schema element.
- *
  */
 public abstract class SchemaElementPanel extends StatusGenericPanel
 {
@@ -141,21 +139,7 @@
    */
   protected Set<String> getAliases(AttributeType attr)
   {
-    Set<String> aliases = new LinkedHashSet<>();
-    Iterable<String> ocNames = attr.getNormalizedNames();
-    String primaryName = attr.getPrimaryName();
-    if (primaryName == null)
-    {
-      primaryName = "";
-    }
-    for (String name : ocNames)
-    {
-      if (!name.equalsIgnoreCase(primaryName))
-      {
-        aliases.add(name);
-      }
-    }
-    return aliases;
+    return getAliases(attr.getNormalizedNames(), attr.getPrimaryName());
   }
 
   /**
@@ -165,14 +149,17 @@
    */
   protected Set<String> getAliases(ObjectClass oc)
   {
+    return getAliases(oc.getNormalizedNames(), oc.getPrimaryName());
+  }
+
+  private Set<String> getAliases(Set<String> names, String primaryName)
+  {
     Set<String> aliases = new LinkedHashSet<>();
-    Iterable<String> ocNames = oc.getNormalizedNames();
-    String primaryName = oc.getPrimaryName();
     if (primaryName == null)
     {
       primaryName = "";
     }
-    for (String name : ocNames)
+    for (String name : names)
     {
       if (!name.equalsIgnoreCase(primaryName))
       {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java b/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
index 89568c6..073b925 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/CommonSchemaElements.java
@@ -32,6 +32,7 @@
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.opendj.ldap.ResultCode;
@@ -72,17 +73,13 @@
      mayExtend=false,
      mayInvoke=true)
 public abstract class CommonSchemaElements implements SchemaFileElement {
-
   /** Indicates whether this definition is declared "obsolete". */
   private final boolean isObsolete;
 
   /** The hash code for this definition. */
   private final int hashCode;
 
-  /**
-   * The set of additional name-value pairs associated with this
-   * definition.
-   */
+  /** The set of additional name-value pairs associated with this definition. */
   private final Map<String, List<String>> extraProperties;
 
   /**
@@ -103,8 +100,6 @@
   /** The lower case name for this definition. */
   private final String lowerName;
 
-
-
   /**
    * Creates a new definition with the provided information.
    * <p>
@@ -138,8 +133,6 @@
       Collection<String> names, String oid, String description,
       boolean isObsolete, Map<String, List<String>> extraProperties)
       throws NullPointerException {
-
-
     // Make sure mandatory parameters are specified.
     if (oid == null) {
       throw new NullPointerException(
@@ -190,8 +183,6 @@
     }
   }
 
-
-
   /**
    * Check if the extra schema properties contain safe filenames.
    *
@@ -218,8 +209,6 @@
     }
   }
 
-
-
   /**
    * Retrieves the primary name for this schema definition.
    *
@@ -227,12 +216,9 @@
    *         <code>null</code> if there is no primary name.
    */
   public final String getPrimaryName() {
-
     return primaryName;
   }
 
-
-
   /**
    * Retrieve the normalized primary name for this schema definition.
    *
@@ -240,12 +226,9 @@
    *         type, or <code>null</code> if there is no primary name.
    */
   public final String getNormalizedPrimaryName() {
-
     return lowerName;
   }
 
-
-
   /**
    * Retrieves an iterable over the set of normalized names that may
    * be used to reference this schema definition. The normalized form
@@ -255,13 +238,10 @@
    * @return Returns an iterable over the set of normalized names that
    *         may be used to reference this schema definition.
    */
-  public final Iterable<String> getNormalizedNames() {
-
+  public final Set<String> getNormalizedNames() {
     return names.keySet();
   }
 
-
-
   /**
    * Retrieves an iterable over the set of user-defined names that may
    * be used to reference this schema definition.
@@ -270,12 +250,9 @@
    *         that may be used to reference this schema definition.
    */
   public final Iterable<String> getUserDefinedNames() {
-
     return names.values();
   }
 
-
-
   /**
    * Indicates whether this schema definition has the specified name.
    *
@@ -285,24 +262,18 @@
    *         this schema definition, or <code>false</code> if not.
    */
   public final boolean hasName(String lowerName) {
-
     return names.containsKey(lowerName);
   }
 
-
-
   /**
    * Retrieves the OID for this schema definition.
    *
    * @return The OID for this schema definition.
    */
   public final String getOID() {
-
     return oid;
   }
 
-
-
   /**
    * Retrieves the name or OID for this schema definition. If it has
    * one or more names, then the primary name will be returned. If it
@@ -333,8 +304,6 @@
     return oid;
   }
 
-
-
   /**
    * Indicates whether this schema definition has the specified name
    * or OID.
@@ -346,12 +315,9 @@
    *         or <code>false</code> if not.
    */
   public final boolean hasNameOrOID(String lowerValue) {
-
     return names.containsKey(lowerValue) || oid.equals(lowerValue);
   }
 
-
-
   /**
    * Retrieves the name of the schema file that contains the
    * definition for this schema definition.
@@ -384,8 +350,6 @@
     return null;
   }
 
-
-
   /**
    * Specifies the name of the schema file that contains the
    * definition for this schema element.  If a schema file is already
@@ -402,8 +366,6 @@
     setExtraProperty(elem, SCHEMA_PROPERTY_FILENAME, schemaFile);
   }
 
-
-
   /**
    * Retrieves the description for this schema definition.
    *
@@ -411,12 +373,9 @@
    *         <code>null</code> if there is no description.
    */
   public final String getDescription() {
-
     return description;
   }
 
-
-
   /**
    * Indicates whether this schema definition is declared "obsolete".
    *
@@ -424,21 +383,15 @@
    *         "obsolete", or <code>false</code> if not.
    */
   public final boolean isObsolete() {
-
     return isObsolete;
   }
 
-
-
-  /** {@inheritDoc} */
   @Override
   public final Map<String, List<String>> getExtraProperties()
   {
     return extraProperties;
   }
 
-
-
   /**
    * Sets the value for an "extra" property for this schema element.
    * If a property already exists with the specified name, then it
@@ -466,8 +419,6 @@
     }
   }
 
-
-
   /**
    * Sets the values for an "extra" property for this schema element.
    * If a property already exists with the specified name, then it
@@ -483,7 +434,6 @@
    */
   public final void setExtraProperty(String name,
                                      List<String> values) {
-
     ifNull(name);
 
     if (values == null || values.isEmpty())
@@ -497,8 +447,6 @@
     }
   }
 
-
-
   /**
    * Indicates whether the provided object is equal to this attribute
    * type. The object will be considered equal if it is an attribute
@@ -523,8 +471,6 @@
     return false;
   }
 
-
-
   /**
    * Retrieves the hash code for this schema definition. It will be
    * based on the sum of the bytes of the OID.

--
Gitblit v1.10.0