From c9083ba8de57af1e1abdec43866956ba25035b36 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 25 Feb 2015 14:52:01 +0000
Subject: [PATCH] Code cleanup

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java |  395 +++++++++++++++++++++++--------------------------------
 1 files changed, 167 insertions(+), 228 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java
index 8c9c9ab..d069c17 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java
@@ -196,36 +196,28 @@
     createLayout();
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public boolean requiresBorder()
   {
     return false;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public boolean requiresScroll()
   {
     return false;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public boolean callConfigurationChangedInBackground()
   {
     return true;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public void toBeDisplayed(boolean visible)
   {
@@ -270,9 +262,8 @@
     add(newObjectClass, gbc);
     newObjectClass.addActionListener(new ActionListener()
     {
-      /**
-       * {@inheritDoc}
-       */
+      /** {@inheritDoc} */
+      @Override
       public void actionPerformed(ActionEvent ev)
       {
         newObjectClassClicked();
@@ -288,9 +279,8 @@
     add(newAttribute, gbc);
     newAttribute.addActionListener(new ActionListener()
     {
-      /**
-       * {@inheritDoc}
-       */
+      /** {@inheritDoc} */
+      @Override
       public void actionPerformed(ActionEvent ev)
       {
         newAttributeClicked();
@@ -324,13 +314,12 @@
     filter = new FilterTextField();
     filter.addKeyListener(new KeyAdapter()
     {
-      /**
-       * {@inheritDoc}
-       */
+      /** {@inheritDoc} */
       @Override
       public void keyReleased(KeyEvent e)
       {
-        if ((e.getKeyCode() == KeyEvent.VK_ENTER) && applyButton.isEnabled())
+        if (e.getKeyCode() == KeyEvent.VK_ENTER
+            && applyButton.isEnabled())
         {
           filter.displayRefreshIcon(FilterTextField.DEFAULT_REFRESH_ICON_TIME);
           repopulateTree(treePane.getTree(), false);
@@ -339,9 +328,8 @@
     });
     filter.addActionListener(new ActionListener()
     {
-      /**
-       * {@inheritDoc}
-       */
+      /** {@inheritDoc} */
+      @Override
       public void actionPerformed(ActionEvent ev)
       {
         filter.displayRefreshIcon(FilterTextField.DEFAULT_REFRESH_ICON_TIME);
@@ -361,9 +349,8 @@
     add(applyButton, gbc);
     applyButton.addActionListener(new ActionListener()
     {
-      /**
-       * {@inheritDoc}
-       */
+      /** {@inheritDoc} */
+      @Override
       public void actionPerformed(ActionEvent ev)
       {
         filter.displayRefreshIcon(FilterTextField.DEFAULT_REFRESH_ICON_TIME);
@@ -415,9 +402,8 @@
     buttonsPanel.add(closeButton, gbc);
     closeButton.addActionListener(new ActionListener()
     {
-      /**
-       * {@inheritDoc}
-       */
+      /** {@inheritDoc} */
+      @Override
       public void actionPerformed(ActionEvent ev)
       {
         closeClicked();
@@ -430,27 +416,21 @@
     return buttonsPanel;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public LocalizableMessage getTitle()
   {
     return INFO_CTRL_PANEL_MANAGE_SCHEMA_TITLE.get();
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public Component getPreferredFocusComponent()
   {
     return filter;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public void closeClicked()
   {
@@ -458,18 +438,14 @@
     super.closeClicked();
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public void okClicked()
   {
     // No ok button
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public GenericDialog.ButtonType getButtonType()
   {
@@ -505,9 +481,8 @@
     entryPane.addSchemaElementSelectionListener(
         new SchemaElementSelectionListener()
     {
-      /**
-       * {@inheritDoc}
-       */
+      /** {@inheritDoc} */
+      @Override
       public void schemaElementSelected(SchemaElementSelectionEvent ev)
       {
         Object element = ev.getSchemaElement();
@@ -520,6 +495,7 @@
     entryPane.addConfigurationElementCreatedListener(
         new ConfigurationElementCreatedListener()
         {
+          @Override
           public void elementCreated(ConfigurationElementCreatedEvent ev)
           {
             configurationElementCreated(ev);
@@ -528,9 +504,8 @@
 
     treePane.getTree().addTreeSelectionListener(new TreeSelectionListener()
     {
-      /**
-       * {@inheritDoc}
-       */
+      /** {@inheritDoc} */
+      @Override
       public void valueChanged(TreeSelectionEvent ev)
       {
         if (!ignoreSelectionEvents)
@@ -573,8 +548,8 @@
               {
                 nonDeletableElementsSelected = true;
               }
-              else if ((node instanceof CustomObjectClassTreeNode) ||
-                  (node instanceof CustomAttributeTreeNode))
+              else if (node instanceof CustomObjectClassTreeNode
+                  || node instanceof CustomAttributeTreeNode)
               {
                 deletableElementsSelected = true;
               }
@@ -621,9 +596,7 @@
     return pane;
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
   @Override
   public void setInfo(ControlPanelInfo info)
   {
@@ -632,9 +605,8 @@
     entryPane.setInfo(info);
   }
 
-  /**
-   * {@inheritDoc}
-   */
+  /** {@inheritDoc} */
+  @Override
   public void configurationChanged(ConfigurationChangeEvent ev)
   {
     final ServerDescriptor desc = ev.getNewDescriptor();
@@ -658,6 +630,7 @@
       lastSchema = schema;
       SwingUtilities.invokeLater(new Runnable()
       {
+        @Override
         public void run()
         {
           repopulateTree(treePane.getTree(), forceScroll);
@@ -922,8 +895,9 @@
       else
       {
         expand = false;
-        if ((parent == standardObjectClasses) || (parent == customObjectClasses)
-            || (parent == configurationObjectClasses))
+        if (parent == standardObjectClasses
+            || parent == customObjectClasses
+            || parent == configurationObjectClasses)
         {
           if (objectClasses.getIndex(parent) == -1)
           {
@@ -937,8 +911,9 @@
           }
           positionUnderObjectClass ++;
         }
-        else if ((parent == standardAttributes) || (parent == customAttributes)
-            || (parent == configurationAttributes))
+        else if (parent == standardAttributes
+            || parent == customAttributes
+            || parent == configurationAttributes)
         {
           if (attributes.getIndex(parent) == -1)
           {
@@ -969,13 +944,13 @@
         {
           DefaultMutableTreeNode node = nodes.get(i).get(name);
           parent.add(node);
-          if ((newSelectionPath == null) &&
-              ((lastSelectedNode != null) || (lastCreatedElement != null)))
+          if (newSelectionPath == null
+              && (lastSelectedNode != null || lastCreatedElement != null))
           {
             if (lastCreatedElement != null)
             {
-              if ((node instanceof CustomObjectClassTreeNode) &&
-                  (lastCreatedElement instanceof ObjectClass))
+              if (node instanceof CustomObjectClassTreeNode
+                  && lastCreatedElement instanceof ObjectClass)
               {
                 if (name.equals(lastCreatedElement.getNameOrOID()))
                 {
@@ -1047,7 +1022,7 @@
     {
       lNumberOfElements.setVisible(false);
     }
-    if ((newSelectionPath == null) && (f.length() > 0))
+    if (newSelectionPath == null && f.length() > 0)
     {
       for (i=0; i<tree.getRowCount(); i++)
       {
@@ -1064,6 +1039,7 @@
 
     SwingUtilities.invokeLater(new Runnable()
     {
+      @Override
       public void run()
       {
         if (forceScroll)
@@ -1087,7 +1063,7 @@
     ViewPositions pos = Utilities.getViewPositions(entryPane);
     TreePath[] paths = treePane.getTree().getSelectionPaths();
     TreePath path = null;
-    if ((paths != null) && (paths.length == 1))
+    if (paths != null && paths.length == 1)
     {
       path = paths[0];
     }
@@ -1180,10 +1156,7 @@
     Utilities.updateViewPositions(pos);
   }
 
-  /**
-   * Adds a popup menu.
-   *
-   */
+  /** Adds a popup menu. */
   private void addPopupMenu()
   {
     popup = new JPopupMenu();
@@ -1191,9 +1164,8 @@
         INFO_CTRL_PANEL_NEW_OBJECTCLASS_MENU.get());
     menuItem.addActionListener(new ActionListener()
     {
-      /**
-       * {@inheritDoc}
-       */
+      /** {@inheritDoc} */
+      @Override
       public void actionPerformed(ActionEvent ev)
       {
         newObjectClassClicked();
@@ -1204,9 +1176,8 @@
         INFO_CTRL_PANEL_NEW_ATTRIBUTE_MENU.get());
     menuItem.addActionListener(new ActionListener()
     {
-      /**
-       * {@inheritDoc}
-       */
+      /** {@inheritDoc} */
+      @Override
       public void actionPerformed(ActionEvent ev)
       {
         newAttributeClicked();
@@ -1218,9 +1189,8 @@
         INFO_CTRL_PANEL_DELETE_SCHEMA_ELEMENT_MENU.get());
     deleteMenuItem.addActionListener(new ActionListener()
     {
-      /**
-       * {@inheritDoc}
-       */
+      /** {@inheritDoc} */
+      @Override
       public void actionPerformed(ActionEvent ev)
       {
         deleteClicked();
@@ -1320,58 +1290,30 @@
     }
   }
 
-  /**
-   * Checks whether a given attribute type must be added or not.  Method used to
-   * do the filtering based on the name.
-   * @param attr the attribute type.
-   * @param attrName the name provided by the user.
-   * @return <CODE>true</CODE> if the attribute must be added and
-   * <CODE>false</CODE> otherwise.
-   */
   private boolean mustAddAttributeName(AttributeType attr, String attrName)
   {
-    ArrayList<String> values = new ArrayList<String>();
-    String oid = attr.getOID();
-    values.add(oid);
-
-    String name = attr.getPrimaryName();
-    if (name != null)
-    {
-      values.add(name);
-    }
-    Iterable<String> names = attr.getNormalizedNames();
-    for (String v : names)
-    {
-      values.add(v);
-    }
-    return  matchFilter(values, attrName, false);
+    return mustAdd(attrName, attr.getOID(), attr.getPrimaryName(), attr.getNormalizedNames());
   }
 
-  /**
-   * Checks whether a given object class must be added or not.  Method used to
-   * do the filtering based on the name.
-   * @param oc the object class.
-   * @param ocName the name provided by the user.
-   * @return <CODE>true</CODE> if the object class must be added and
-   * <CODE>false</CODE> otherwise.
-   */
   private boolean mustAddObjectClassName(ObjectClass oc, String ocName)
   {
-    ArrayList<String> values = new ArrayList<String>();
-    String oid = oc.getOID();
-    values.add(oid);
+    return mustAdd(ocName, oc.getOID(), oc.getPrimaryName(), oc.getNormalizedNames());
+  }
 
-    String name = oc.getPrimaryName();
-    if (name != null)
+  private boolean mustAdd(String name, String oid, String primaryName, Iterable<String> names)
+  {
+    ArrayList<String> values = new ArrayList<String>();
+    values.add(oid);
+    if (primaryName != null)
     {
-      values.add(name);
+      values.add(primaryName);
     }
-    Iterable<String> names = oc.getNormalizedNames();
     for (String v : names)
     {
       values.add(v);
     }
-    return  matchFilter(values, ocName, false);
+
+    return matchFilter(values, name, false);
   }
 
   /**
@@ -1395,13 +1337,7 @@
       }
       else if (TYPE.equals(filterType))
       {
-        String[] elements = f.split("[ ,]");
-        String text =
-          StandardAttributePanel.getTypeValue(attr).toString().toLowerCase();
-        for (int i=0; i<elements.length && mustAdd; i++)
-        {
-          mustAdd = text.indexOf(elements[i].toLowerCase()) != -1;
-        }
+        mustAdd = mustAddType(f, StandardAttributePanel.getTypeValue(attr));
       }
       else
       {
@@ -1411,6 +1347,25 @@
     return mustAdd;
   }
 
+  private boolean mustAddType(String filter, LocalizableMessage typeValue)
+  {
+    String[] elements = filter.split("[ ,]");
+    String text = typeValue.toString().toLowerCase();
+    return mustAdd(elements, text);
+  }
+
+  private boolean mustAdd(String[] elements, String text)
+  {
+    for (String elem : elements)
+    {
+      if (!text.contains(elem.toLowerCase()))
+      {
+        return false;
+      }
+    }
+    return true;
+  }
+
   /**
    * Check whether the provided object class must be added or not.
    * @param oc the objectclass.
@@ -1431,58 +1386,16 @@
       }
       else if (TYPE.equals(filterType))
       {
-        String[] elements = f.split("[ ,]");
-        String text =
-          StandardObjectClassPanel.getTypeValue(oc).toString().toLowerCase();
-        for (int i=0; i<elements.length && mustAdd; i++)
-        {
-          mustAdd = text.indexOf(elements[i].toLowerCase()) != -1;
-        }
+        mustAdd = mustAddType(f, StandardObjectClassPanel.getTypeValue(oc));
       }
       else if (REQUIRED_ATTRIBUTES.equals(filterType) ||
           OPTIONAL_ATTRIBUTES.equals(filterType))
       {
-        String[] attrValues = f.split(" ");
-        Set<AttributeType> definedAttrs;
-        if (REQUIRED_ATTRIBUTES.equals(filterType))
-        {
-          definedAttrs = oc.getRequiredAttributeChain();
-        }
-        else
-        {
-          definedAttrs = oc.getOptionalAttributeChain();
-        }
-        for (String attrName : attrValues)
-        {
-          mustAdd = false;
-          for (AttributeType attr : definedAttrs)
-          {
-            mustAdd = mustAddAttributeName(attr, attrName);
-            if (mustAdd)
-            {
-              break;
-            }
-          }
-          if (!mustAdd)
-          {
-            break;
-          }
-        }
+        mustAdd = mustAddAttributeName(oc, f, filterType);
       }
       else if (CHILD_CLASS.equals(filterType))
       {
-        mustAdd = false;
-        for (ObjectClass o : lastSchema.getObjectClasses().values())
-        {
-          if (isDescendant(oc, o))
-          {
-            mustAdd = mustAddObjectClassName(o, f);
-            if (mustAdd)
-            {
-              break;
-            }
-          }
-        }
+        mustAdd = mustAddAnyObjectClassName(oc, f);
       }
       else if (PARENT_CLASS.equals(filterType))
       {
@@ -1496,22 +1409,68 @@
     return mustAdd;
   }
 
-  private boolean mustAddParentObjectClassName(ObjectClass oc, String f)
+  private boolean mustAddAnyObjectClassName(ObjectClass oc, String f)
   {
-    boolean mustAdd = false;
-    Set<ObjectClass> parents = oc.getSuperiorClasses();
-    for (ObjectClass parent : parents)
+    for (ObjectClass o : lastSchema.getObjectClasses().values())
     {
-      if (mustAddObjectClassName(parent, f) ||
-          mustAddParentObjectClassName(parent, f))
+      if (isDescendant(oc, o) && mustAddObjectClassName(o, f))
       {
-        mustAdd = true;
+        return true;
+      }
+    }
+    return false;
+  }
+
+  private boolean mustAddAttributeName(ObjectClass oc, String f, Object filterType)
+  {
+    Set<AttributeType> definedAttrs;
+    if (REQUIRED_ATTRIBUTES.equals(filterType))
+    {
+      definedAttrs = oc.getRequiredAttributeChain();
+    }
+    else
+    {
+      definedAttrs = oc.getOptionalAttributeChain();
+    }
+    return mustAddAttributeName(f, definedAttrs);
+  }
+
+  private boolean mustAddAttributeName(String f, Set<AttributeType> definedAttrs)
+  {
+    boolean mustAdd = true;
+    String[] attrValues = f.split(" ");
+    for (String attrName : attrValues)
+    {
+      mustAdd = false;
+      for (AttributeType attr : definedAttrs)
+      {
+        mustAdd = mustAddAttributeName(attr, attrName);
+        if (mustAdd)
+        {
+          break;
+        }
+      }
+      if (!mustAdd)
+      {
         break;
       }
     }
     return mustAdd;
   }
 
+  private boolean mustAddParentObjectClassName(ObjectClass oc, String f)
+  {
+    for (ObjectClass parent : oc.getSuperiorClasses())
+    {
+      if (mustAddObjectClassName(parent, f) ||
+          mustAddParentObjectClassName(parent, f))
+      {
+        return true;
+      }
+    }
+    return false;
+  }
+
   /**
    * Finds out if a class is descendant of another class using equality of
    * pointers.
@@ -1548,39 +1507,23 @@
    */
   private boolean mustAdd(MatchingRule matchingRule)
   {
-    boolean mustAdd = true;
     String f = filter.getText().trim();
     if (f.length () > 0)
     {
       if (NAME.equals(filterAttribute.getSelectedItem()))
       {
-        ArrayList<String> values = new ArrayList<String>();
-        String oid = matchingRule.getOID();
-        values.add(oid);
-
-        String name = matchingRule.getNameOrOID();
-        if (name != null)
-        {
-          values.add(name);
-        }
-        mustAdd = matchFilter(values, f, false);
+        return mustAdd(f, matchingRule.getOID(), matchingRule.getNameOrOID());
       }
       else if (TYPE.equals(filterAttribute.getSelectedItem()))
       {
-        String[] elements = f.split("[ ,]");
-        String text =
-          MatchingRulePanel.getTypeValue(matchingRule).toString().toLowerCase();
-        for (int i=0; i<elements.length && mustAdd; i++)
-        {
-          mustAdd = text.indexOf(elements[i].toLowerCase()) != -1;
-        }
+        return mustAddType(f, MatchingRulePanel.getTypeValue(matchingRule));
       }
       else
       {
-        mustAdd = false;
+        return false;
       }
     }
-    return mustAdd;
+    return true;
   }
 
   /**
@@ -1591,51 +1534,47 @@
    */
   private boolean mustAdd(AttributeSyntax<?> syntax)
   {
-    boolean mustAdd = true;
     String f = filter.getText().trim();
     if (f.length () > 0)
     {
       if (NAME.equals(filterAttribute.getSelectedItem()))
       {
-        ArrayList<String> values = new ArrayList<String>();
-        String oid = syntax.getOID();
-        values.add(oid);
-
-        String name = syntax.getName();
-        if (name != null)
-        {
-          values.add(name);
-        }
-        mustAdd = matchFilter(values, f, false);
+        return mustAdd(f, syntax.getOID(), syntax.getName());
       }
       else
       {
-        mustAdd = false;
+        return false;
       }
     }
-    return mustAdd;
+    return true;
+  }
+
+  private boolean mustAdd(String f, String oid, String name)
+  {
+    ArrayList<String> values = new ArrayList<String>(2);
+    values.add(oid);
+    if (name != null)
+    {
+      values.add(name);
+    }
+
+    return matchFilter(values, f, false);
   }
 
   private boolean matchFilter(Collection<String> values, String filter,
       boolean exact)
   {
-    boolean matchFilter = false;
     for (String value : values)
     {
-      if (exact)
-      {
-        matchFilter = value.equalsIgnoreCase(filter);
-      }
-      else
-      {
-        matchFilter = value.toLowerCase().indexOf(filter.toLowerCase()) != -1;
-      }
+      boolean matchFilter = exact
+          ? value.equalsIgnoreCase(filter)
+          : value.toLowerCase().contains(filter.toLowerCase());
       if (matchFilter)
       {
         break;
       }
     }
-    return matchFilter;
+    return false;
   }
 
   private DefaultMutableTreeNode getRoot(JTree tree)
@@ -1656,6 +1595,7 @@
       panel.addConfigurationElementCreatedListener(
           new ConfigurationElementCreatedListener()
           {
+            @Override
             public void elementCreated(ConfigurationElementCreatedEvent ev)
             {
               configurationElementCreated(ev);
@@ -1678,6 +1618,7 @@
       panel.addConfigurationElementCreatedListener(
           new ConfigurationElementCreatedListener()
           {
+            @Override
             public void elementCreated(ConfigurationElementCreatedEvent ev)
             {
               configurationElementCreated(ev);
@@ -1736,9 +1677,7 @@
   {
     private static final long serialVersionUID = -3390568254259441766L;
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     @Override
     public Component getTreeCellRendererComponent(JTree tree, Object value,
         boolean isSelected, boolean isExpanded, boolean isLeaf, int row,
@@ -1800,7 +1739,7 @@
       for (int i=0; i<lOrderedAttributes.size(); i++)
       {
         AttributeType parent = lOrderedAttributes.get(i).getSuperiorType();
-        while ((parent != null) && (index == -1))
+        while (parent != null && index == -1)
         {
           if (parent.equals(attr))
           {

--
Gitblit v1.10.0