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

---
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java                   |   27 ++-
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java            |  180 ++++++++-------------
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java                 |  187 ++++++++---------------
 opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/renderer/LDAPEntryTableCellRenderer.java |   28 +--
 4 files changed, 162 insertions(+), 260 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
index 510b0a4..5b0448a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
@@ -113,7 +113,7 @@
     // Find password modifications
     for (ModificationItem mod : modifications)
     {
-      if (mod.getAttribute().getID().equalsIgnoreCase("userPassword"))
+      if ("userPassword".equalsIgnoreCase(mod.getAttribute().getID()))
       {
         passwordModification = mod;
         break;
@@ -138,37 +138,37 @@
     return hasModifications;
   }
 
-  /** {@inheritDoc} */
+  @Override
   public Type getType()
   {
     return Type.MODIFY_ENTRY;
   }
 
-  /** {@inheritDoc} */
+  @Override
   public Set<String> getBackends()
   {
     return backendSet;
   }
 
-  /** {@inheritDoc} */
+  @Override
   public LocalizableMessage getTaskDescription()
   {
     return INFO_CTRL_PANEL_MODIFY_ENTRY_TASK_DESCRIPTION.get(oldEntry.getDN());
   }
 
-  /** {@inheritDoc} */
+  @Override
   protected String getCommandLinePath()
   {
     return null;
   }
 
-  /** {@inheritDoc} */
+  @Override
   protected ArrayList<String> getCommandLineArguments()
   {
     return new ArrayList<>();
   }
 
-  /** {@inheritDoc} */
+  @Override
   public boolean canLaunch(Task taskToBeLaunched,
       Collection<LocalizableMessage> incompatibilityReasons)
   {
@@ -190,13 +190,13 @@
     return true;
   }
 
-  /** {@inheritDoc} */
+  @Override
   public boolean regenerateDescriptor()
   {
     return false;
   }
 
-  /** {@inheritDoc} */
+  @Override
   public void runTask()
   {
     state = State.RUNNING;
@@ -216,6 +216,7 @@
 
           SwingUtilities.invokeLater(new Runnable()
           {
+            @Override
             public void run()
             {
               printEquivalentCommandToModify(newEntry.getName(), modifications,
@@ -231,6 +232,7 @@
 
           SwingUtilities.invokeLater(new Runnable()
           {
+            @Override
             public void run()
             {
               getProgressDialog().appendProgressHtml(
@@ -257,7 +259,7 @@
     }
   }
 
-  /** {@inheritDoc} */
+  @Override
   public void postOperation()
   {
     if (lastException == null
@@ -340,6 +342,7 @@
 
     SwingUtilities.invokeLater(new Runnable()
     {
+      @Override
       public void run()
       {
         printEquivalentRenameCommand(oldDN, newEntry.getName(), useAdminCtx);
@@ -357,6 +360,7 @@
 
     SwingUtilities.invokeLater(new Runnable()
     {
+      @Override
       public void run()
       {
         getProgressDialog().appendProgressHtml(
@@ -370,13 +374,13 @@
       }
     });
 
-
     ModificationItem[] mods = new ModificationItem[originalMods.size()];
     originalMods.toArray(mods);
     if (mods.length > 0)
     {
       SwingUtilities.invokeLater(new Runnable()
       {
+        @Override
         public void run()
         {
           DN dn = newEntry.getName();
@@ -392,6 +396,7 @@
 
       SwingUtilities.invokeLater(new Runnable()
       {
+        @Override
         public void run()
         {
           getProgressDialog().appendProgressHtml(
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java
index 945bd86..e61a77e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java
@@ -251,46 +251,48 @@
     createLayout();
   }
 
-  /** {@inheritDoc} */
+  @Override
   public Component getPreferredFocusComponent()
   {
     return null;
   }
 
-  /** {@inheritDoc} */
+  @Override
   public boolean requiresBorder()
   {
     return false;
   }
 
-  /**
-   * Creates the layout of the panel (but the contents are not populated here).
-   */
+  /** Creates the layout of the panel (but the contents are not populated here). */
   private void createLayout()
   {
     dropTargetListener = new DropTargetListener()
     {
-      /** {@inheritDoc} */
+      @Override
       public void dragEnter(DropTargetDragEvent e)
       {
+        // no-op
       }
 
-      /** {@inheritDoc} */
+      @Override
       public void dragExit(DropTargetEvent e)
       {
+        // no-op
       }
 
-      /** {@inheritDoc} */
+      @Override
       public void dragOver(DropTargetDragEvent e)
       {
+        // no-op
       }
 
-      /** {@inheritDoc} */
+      @Override
       public void dropActionChanged(DropTargetDragEvent e)
       {
+        // no-op
       }
 
-      /** {@inheritDoc} */
+      @Override
       public void drop(DropTargetDropEvent e)
       {
         try {
@@ -364,7 +366,7 @@
     showOnlyAttrsWithValues.setSelected(displayOnlyWithAttrs);
     showOnlyAttrsWithValues.addActionListener(new ActionListener()
     {
-       /** {@inheritDoc} */
+       @Override
        public void actionPerformed(ActionEvent ev)
        {
          updateAttributeVisibility(!showOnlyAttrsWithValues.isSelected());
@@ -400,7 +402,7 @@
     add(scrollAttributes, gbc);
   }
 
-  /** {@inheritDoc} */
+  @Override
   public void update(CustomSearchResult sr, boolean isReadOnly, TreePath path)
   {
     boolean sameEntry = false;
@@ -432,7 +434,6 @@
     hmComponents.clear();
     requiredAttrs.clear();
 
-
     // Build the attributes panel.
     Collection<String> sortedAttributes = getSortedAttributes(sr, isReadOnly);
     if (isReadOnly)
@@ -507,8 +508,7 @@
         JComponent comp = getReadWriteComponent(attr, values);
 
         gbc.weightx = 0.0;
-        if (attr.equalsIgnoreCase(
-            ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME))
+        if (ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME.equalsIgnoreCase(attr))
         {
           int nOcs = 0;
           for (Object o : values)
@@ -599,7 +599,7 @@
 
     SwingUtilities.invokeLater(new Runnable()
     {
-      /** {@inheritDoc} */
+      @Override
       public void run()
       {
         if (p != null && scrollAttributes.getViewport().contains(p))
@@ -706,8 +706,8 @@
       }
     }
     // Handle the root entry separately: most of its attributes are operational
-    // so we filter a list of harcoded attributes.
-    boolean isRootEntry = sr.getDN().equals("");
+    // so we filter a list of hardcoded attributes.
+    boolean isRootEntry = "".equals(sr.getDN());
     Schema schema = getInfo().getServerDescriptor().getSchema();
     if (isRootEntry)
     {
@@ -754,15 +754,10 @@
       }
       // Now try to put first the attributes for which we have a friendly
       // name (the most common ones).
-      updateAttributes(attributes, requiredAttributes, entryAttrs,
-          attrsWithNoOptions, true);
-      updateAttributes(attributes, requiredAttributes, entryAttrs,
-          attrsWithNoOptions, false);
-      updateAttributes(attributes, allowedAttributes, entryAttrs,
-          attrsWithNoOptions, true);
-      updateAttributes(attributes, allowedAttributes, entryAttrs,
-          attrsWithNoOptions, false);
-
+      updateAttributes(attributes, requiredAttributes, entryAttrs, attrsWithNoOptions, true);
+      updateAttributes(attributes, requiredAttributes, entryAttrs, attrsWithNoOptions, false);
+      updateAttributes(attributes, allowedAttributes, entryAttrs, attrsWithNoOptions, true);
+      updateAttributes(attributes, allowedAttributes, entryAttrs, attrsWithNoOptions, false);
 
       attributes.addAll(entryAttrs);
       attributes.add("aci");
@@ -815,17 +810,13 @@
         {
           attributes.add(entryAttrs.get(index));
         }
+        else if (hasCertificateSyntax(attr, getInfo().getServerDescriptor().getSchema()))
+        {
+          attributes.add(attr + ";binary");
+        }
         else
         {
-          if (!hasCertificateSyntax(attr,
-              getInfo().getServerDescriptor().getSchema()))
-          {
-            attributes.add(attr);
-          }
-          else
-          {
-            attributes.add(attr+";binary");
-          }
+          attributes.add(attr);
         }
       }
     }
@@ -847,8 +838,7 @@
       gbc.weightx = 1.0;
       gbc.gridx = 0;
 
-      if (attrName.equalsIgnoreCase(
-          ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME))
+      if (ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME.equalsIgnoreCase(attrName))
       {
         ObjectClassCellPanel ocPanel = new ObjectClassCellPanel();
         Schema schema = getInfo().getServerDescriptor().getSchema();
@@ -898,7 +888,7 @@
         pane.setValue(binaryValue, isImage);
         pane.addEditActionListener(new ActionListener()
         {
-          /** {@inheritDoc} */
+          @Override
           public void actionPerformed(ActionEvent ev)
           {
             if (binaryDlg == null)
@@ -949,8 +939,7 @@
       gbc.fill = GridBagConstraints.HORIZONTAL;
       gbc.weightx = 1.0;
       gbc.gridx = 0;
-      if (attrName.equalsIgnoreCase(
-          ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME))
+      if (ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME.equalsIgnoreCase(attrName))
       {
         final ObjectClassCellPanel ocCellPanel = new ObjectClassCellPanel();
         Schema schema = getInfo().getServerDescriptor().getSchema();
@@ -967,7 +956,7 @@
         ocCellPanel.addEditActionListener(new ActionListener()
         {
           private ObjectClassValue newValue;
-          /** {@inheritDoc} */
+          @Override
           public void actionPerformed(ActionEvent ev)
           {
             if (editOcDlg == null)
@@ -1005,7 +994,7 @@
       else if (isPassword(attrName) || isConfirmPassword(attrName))
       {
         JPasswordField pf = Utilities.createPasswordField();
-        if (!o.equals(""))
+        if (!"".equals(o))
         {
           pf.setText(getPasswordStringValue(o));
         }
@@ -1059,7 +1048,7 @@
             final JButton browse = Utilities.createButton(
                 INFO_CTRL_PANEL_BROWSE_BUTTON_LABEL.get());
             browse.addActionListener(new AddBrowseClickedActionListener(ta, attrName));
-            if (attrName.equalsIgnoreCase(ServerConstants.ATTR_UNIQUE_MEMBER_LC))
+            if (ServerConstants.ATTR_UNIQUE_MEMBER_LC.equalsIgnoreCase(attrName))
             {
               browse.setText(
                   INFO_CTRL_PANEL_ADD_MEMBERS_BUTTON.get().toString());
@@ -1082,10 +1071,11 @@
         {
           pane.setValue(binaryValue, isImage);
         }
+
         pane.addEditActionListener(new ActionListener()
         {
           private BinaryValue newValue;
-          /** {@inheritDoc} */
+          @Override
           public void actionPerformed(ActionEvent ev)
           {
             if (editBinaryDlg == null)
@@ -1103,7 +1093,7 @@
             {
               // We use an empty binary array to not breaking the logic:
               // it means that there is no value for the attribute.
-              if (binaryValue != null && binaryValue.length > 0)
+              if (binaryValue.length > 0)
               {
                 newValue = BinaryValue.createBase64(binaryValue);
                 editBinaryPanel.setValue(attrName, newValue);
@@ -1128,7 +1118,7 @@
         });
         pane.addDeleteActionListener(new ActionListener()
         {
-          /** {@inheritDoc} */
+          @Override
           public void actionPerformed(ActionEvent ev)
           {
             pane.setValue((byte[])null, false);
@@ -1181,18 +1171,16 @@
     return false;
   }
 
-  /** {@inheritDoc} */
+  @Override
   public GenericDialog.ButtonType getButtonType()
   {
     return GenericDialog.ButtonType.NO_BUTTON;
   }
 
-  /** {@inheritDoc} */
+  @Override
   public Entry getEntry() throws OpenDsException
   {
-    Entry entry = null;
-
-    ArrayList<LocalizableMessage> errors = new ArrayList<>();
+    final List<LocalizableMessage> errors = new ArrayList<>();
 
     try
     {
@@ -1208,7 +1196,6 @@
       setPrimaryValid(hmLabels.get(attrName));
     }
 
-
     // Check passwords
     for (String attrName : lastUserPasswords.keySet())
     {
@@ -1227,7 +1214,7 @@
     }
     for (String attrName : requiredAttrs)
     {
-      if (!hasValue(attrName))
+      if (!!getValues(attrName).isEmpty())
       {
         setPrimaryInvalid(hmLabels.get(attrName));
         errors.add(ERR_CTRL_PANEL_ATTRIBUTE_REQUIRED.get(
@@ -1240,29 +1227,19 @@
       throw new CheckEntrySyntaxException(errors);
     }
 
-    LDIFImportConfig ldifImportConfig = null;
-    try
+    final String ldif = getLDIF();
+    try (LDIFImportConfig ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
+        LDIFReader reader = new LDIFReader(ldifImportConfig))
     {
-      String ldif = getLDIF();
-
-      ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
-      LDIFReader reader = new LDIFReader(ldifImportConfig);
-      entry = reader.readEntry(checkSchema());
+      final Entry entry = reader.readEntry(checkSchema());
       addValuesInRDN(entry);
+      return entry;
     }
     catch (IOException ioe)
     {
       throw new OnlineUpdateException(
           ERR_CTRL_PANEL_ERROR_CHECKING_ENTRY.get(ioe), ioe);
     }
-    finally
-    {
-      if (ldifImportConfig != null)
-      {
-        ldifImportConfig.close();
-      }
-    }
-    return entry;
   }
 
   private List<String> getDisplayedStringValues(String attrName)
@@ -1395,8 +1372,8 @@
 
   private boolean mustAddBrowseButton(String attrName)
   {
-    if (attrName.equalsIgnoreCase(ServerConstants.ATTR_UNIQUE_MEMBER_LC)
-        || attrName.equalsIgnoreCase("ds-target-group-dn"))
+    if (ServerConstants.ATTR_UNIQUE_MEMBER_LC.equalsIgnoreCase(attrName)
+        || "ds-target-group-dn".equalsIgnoreCase(attrName))
     {
       return true;
     }
@@ -1408,13 +1385,12 @@
       String syntaxName = attr.getSyntax().getName();
       if (syntaxName != null)
       {
-        return syntaxName.equalsIgnoreCase(SchemaConstants.SYNTAX_DN_NAME);
+        return SchemaConstants.SYNTAX_DN_NAME.equalsIgnoreCase(syntaxName);
       }
     }
     return false;
   }
 
-  /** {@inheritDoc} */
   @Override
   protected List<Object> getValues(String attrName)
   {
@@ -1446,7 +1422,7 @@
     }
   }
 
-  /** {@inheritDoc} */
+  @Override
   protected String getDisplayedDN()
   {
     StringBuilder sb = new StringBuilder();
@@ -1514,25 +1490,13 @@
         DN parent = oldDN.parent();
         if (!avas.isEmpty())
         {
-          RDN newRDN = new RDN(avas);
-
-          DN newDN;
-          if (parent == null)
-          {
-            newDN = DN.rootDN().child(newRDN);
-          }
-          else
-          {
-            newDN = parent.child(newRDN);
-          }
+          DN newParent = parent != null ? parent : DN.rootDN();
+          DN newDN = newParent.child(new RDN(avas));
           sb.append(newDN);
         }
-        else
+        else if (parent != null)
         {
-          if (parent != null)
-          {
-            sb.append(",").append(parent);
-          }
+          sb.append(",").append(parent);
         }
       }
     }
@@ -1578,12 +1542,12 @@
       previousTitle = browseEntriesPanel.getTitle();
       previousFilter = browseEntriesPanel.getFilter();
     }
-    if (attrName.equalsIgnoreCase(ServerConstants.ATTR_UNIQUE_MEMBER_LC))
+    if (ServerConstants.ATTR_UNIQUE_MEMBER_LC.equalsIgnoreCase(attrName))
     {
       title = INFO_CTRL_PANEL_ADD_MEMBERS_LABEL.get();
       filter = LDAPEntrySelectionPanel.Filter.USERS;
     }
-    else if (attrName.equalsIgnoreCase("ds-target-group-dn"))
+    else if ("ds-target-group-dn".equalsIgnoreCase(attrName))
     {
       title = INFO_CTRL_PANEL_CHOOSE_REFERENCE_GROUP.get();
       filter = LDAPEntrySelectionPanel.Filter.DYNAMIC_GROUPS;
@@ -1736,17 +1700,7 @@
       }
       else
       {
-        List<EditorComponent> editors = hmEditors.get(attrName);
-        boolean hasValue = false;
-
-        for (EditorComponent editor : editors)
-        {
-          hasValue = hasValue(editor);
-          if (hasValue)
-          {
-            break;
-          }
-        }
+        boolean hasValue = hasValue(hmEditors.get(attrName));
         label.setVisible(hasValue);
         comp.setVisible(hasValue);
       }
@@ -1754,9 +1708,16 @@
     repaint();
   }
 
-  private boolean hasValue(String attrName)
+  private boolean hasValue(List<EditorComponent> editors)
   {
-    return !getValues(attrName).isEmpty();
+    for (EditorComponent editor : editors)
+    {
+      if (hasValue(editor))
+      {
+        return true;
+      }
+    }
+    return false;
   }
 
   private boolean hasValue(EditorComponent editor)
@@ -1789,6 +1750,7 @@
       this.attrName = attrName;
     }
 
+    @Override
     public void actionPerformed(ActionEvent ev)
     {
       addBrowseClicked(attrName, tc);
@@ -1799,7 +1761,6 @@
    * A class that makes an association between a component (JTextField, a
    * BinaryCellValue...) and the associated value that will be used to create
    * the modified entry corresponding to the contents of the panel.
-   *
    */
   class EditorComponent
   {
@@ -1814,19 +1775,19 @@
       comp = tf;
       tf.getDocument().addDocumentListener(new DocumentListener()
       {
-        /** {@inheritDoc} */
+        @Override
         public void insertUpdate(DocumentEvent ev)
         {
           notifyListeners();
         }
 
-        /** {@inheritDoc} */
+        @Override
         public void changedUpdate(DocumentEvent ev)
         {
           notifyListeners();
         }
 
-        /** {@inheritDoc} */
+        @Override
         public void removeUpdate(DocumentEvent ev)
         {
           notifyListeners();
@@ -1925,4 +1886,3 @@
     }
   }
 }
-
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
index 0e13d77..c513db6 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
@@ -66,9 +66,7 @@
 import org.opends.server.util.LDIFReader;
 import org.opends.server.util.ServerConstants;
 
-/**
- * The panel displaying a table view of an LDAP entry.
- */
+/** The panel displaying a table view of an LDAP entry. */
 public class TableViewEntryPanel extends ViewEntryPanel
 {
   private static final long serialVersionUID = 2135331526526472175L;
@@ -83,25 +81,20 @@
   private JLabel requiredLabel;
   private JCheckBox showOnlyAttrsWithValues;
 
-  /**
-   * Default constructor.
-   *
-   */
+  /** Default constructor. */
   public TableViewEntryPanel()
   {
     super();
     createLayout();
   }
 
-  /** {@inheritDoc} */
+  @Override
   public Component getPreferredFocusComponent()
   {
     return table;
   }
 
-  /**
-   * Creates the layout of the panel (but the contents are not populated here).
-   */
+  /** Creates the layout of the panel (but the contents are not populated here). */
   private void createLayout()
   {
     GridBagConstraints gbc = new GridBagConstraints();
@@ -122,7 +115,7 @@
     showOnlyAttrsWithValues.setSelected(displayOnlyWithAttrs);
     showOnlyAttrsWithValues.addActionListener(new ActionListener()
     {
-       /** {@inheritDoc} */
+       @Override
        public void actionPerformed(ActionEvent ev)
        {
          updateAttributeVisibility();
@@ -160,7 +153,7 @@
     add(scroll, gbc);
   }
 
-  /** {@inheritDoc} */
+  @Override
   public void update(CustomSearchResult sr, boolean isReadOnly, TreePath path)
   {
     boolean sameEntry = false;
@@ -184,6 +177,7 @@
     Utilities.updateScrollMode(scroll, table);
     SwingUtilities.invokeLater(new Runnable()
     {
+      @Override
       public void run()
       {
         if (p != null && scroll.getViewport().contains(p))
@@ -195,13 +189,13 @@
     });
   }
 
-  /** {@inheritDoc} */
+  @Override
   public GenericDialog.ButtonType getButtonType()
   {
     return GenericDialog.ButtonType.NO_BUTTON;
   }
 
-  /** {@inheritDoc} */
+  @Override
   public Entry getEntry() throws OpenDsException
   {
     if (SwingUtilities.isEventDispatchThread())
@@ -214,41 +208,31 @@
       {
         SwingUtilities.invokeAndWait(new Runnable()
         {
+          @Override
           public void run()
           {
             editor.stopCellEditing();
           }
         });
       }
-      catch (Throwable t)
+      catch (Throwable ignore)
       {
+        // ignored
       }
     }
-    Entry entry = null;
-    LDIFImportConfig ldifImportConfig = null;
-    try
+    String ldif = getLDIF();
+    try (LDIFImportConfig ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
+        LDIFReader reader = new LDIFReader(ldifImportConfig))
     {
-      String ldif = getLDIF();
-
-      ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
-      LDIFReader reader = new LDIFReader(ldifImportConfig);
-      entry = reader.readEntry(checkSchema());
+      Entry entry = reader.readEntry(checkSchema());
       addValuesInRDN(entry);
-
+      return entry;
     }
     catch (IOException ioe)
     {
       throw new OnlineUpdateException(
           ERR_CTRL_PANEL_ERROR_CHECKING_ENTRY.get(ioe), ioe);
     }
-    finally
-    {
-      if (ldifImportConfig != null)
-      {
-        ldifImportConfig.close();
-      }
-    }
-    return entry;
   }
 
   /**
@@ -271,7 +255,7 @@
     return sb.toString();
   }
 
-  /** {@inheritDoc} */
+  @Override
   protected String getDisplayedDN()
   {
     StringBuilder sb = new StringBuilder();
@@ -315,10 +299,9 @@
             for (int i=0; i<table.getRowCount(); i++)
             {
               String attrName = (String)table.getValueAt(i, 0);
-              if (isPassword(attrName) ||
-                  attrName.equals(
-                      ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME) ||
-                  !table.isCellEditable(i, 1))
+              if (isPassword(attrName)
+                  || ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME.equals(attrName)
+                  || !table.isCellEditable(i, 1))
               {
                 continue;
               }
@@ -338,25 +321,13 @@
         DN parent = oldDN.parent();
         if (!avas.isEmpty())
         {
-          RDN newRDN = new RDN(avas);
-
-          DN newDN;
-          if (parent == null)
-          {
-            newDN = DN.rootDN().child(newRDN);
-          }
-          else
-          {
-            newDN = parent.child(newRDN);
-          }
+          DN newParent = (parent != null) ? parent : DN.rootDN();
+          DN newDN = newParent.child(new RDN(avas));
           sb.append(newDN);
         }
-        else
+        else if (parent != null)
         {
-          if (parent != null)
-          {
-            sb.append(",").append(parent);
-          }
+          sb.append(",").append(parent);
         }
       }
     }
@@ -402,7 +373,7 @@
     tableModel.updateAttributeVisibility();
   }
 
-  /** {@inheritDoc} */
+  @Override
   protected List<Object> getValues(String attrName)
   {
     return tableModel.getValues(attrName);
@@ -436,13 +407,14 @@
      * Updates the table model contents and sorts its contents depending on the
      * sort options set by the user.
      */
+    @Override
     public void forceResort()
     {
       updateDataArray();
       fireTableDataChanged();
     }
 
-    /** {@inheritDoc} */
+    @Override
     public int compare(AttributeValuePair desc1, AttributeValuePair desc2)
     {
       int result;
@@ -472,19 +444,13 @@
     {
       if (o1 == null)
       {
-        if (o2 == null)
-        {
-          return 0;
-        }
-        else
-        {
-          return -1;
-        }
+        return o2 == null ? 0 : -1;
       }
       else if (o2 == null)
       {
         return 1;
       }
+
       if (o1 instanceof ObjectClassValue)
       {
         o1 = renderer.getString((ObjectClassValue)o1);
@@ -509,6 +475,7 @@
       {
         o2 = renderer.getString((byte[])o2);
       }
+
       if (o1.getClass().equals(o2.getClass()))
       {
         if (o1 instanceof String)
@@ -523,53 +490,40 @@
         {
           return ((Long)o1).compareTo((Long)o2);
         }
-        else
-        {
-          return String.valueOf(o1).compareTo(String.valueOf(o2));
-        }
       }
-      else
-      {
-        return String.valueOf(o1).compareTo(String.valueOf(o2));
-      }
+      return String.valueOf(o1).compareTo(String.valueOf(o2));
     }
 
-    /** {@inheritDoc} */
+    @Override
     public int getColumnCount()
     {
       return COLUMN_NAMES.length;
     }
 
-    /** {@inheritDoc} */
+    @Override
     public int getRowCount()
     {
       return dataArray.size();
     }
 
-    /** {@inheritDoc} */
+    @Override
     public Object getValueAt(int row, int col)
     {
-      if (col == 0)
-      {
-        return dataArray.get(row).attrName;
-      }
-      else
-      {
-        return dataArray.get(row).value;
-      }
+      AttributeValuePair attrValuePair = dataArray.get(row);
+      return col == 0 ? attrValuePair.attrName : attrValuePair.value;
     }
 
-    /** {@inheritDoc} */
+    @Override
     public String getColumnName(int col) {
       return COLUMN_NAMES[col];
     }
 
-
     /**
      * Returns whether the sort is ascending or descending.
      * @return <CODE>true</CODE> if the sort is ascending and <CODE>false</CODE>
      * otherwise.
      */
+    @Override
     public boolean isSortAscending()
     {
       return sortAscending;
@@ -579,6 +533,7 @@
      * Sets whether to sort ascending of descending.
      * @param sortAscending whether to sort ascending or descending.
      */
+    @Override
     public void setSortAscending(boolean sortAscending)
     {
       this.sortAscending = sortAscending;
@@ -588,6 +543,7 @@
      * Returns the column index used to sort.
      * @return the column index used to sort.
      */
+    @Override
     public int getSortColumn()
     {
       return sortColumn;
@@ -597,19 +553,20 @@
      * Sets the column index used to sort.
      * @param sortColumn column index used to sort..
      */
+    @Override
     public void setSortColumn(int sortColumn)
     {
       this.sortColumn = sortColumn;
     }
 
-    /** {@inheritDoc} */
+    @Override
     public boolean isCellEditable(int row, int col) {
       return col != 0
           && !isReadOnly
           && !schemaReadOnlyAttributesLowerCase.contains(dataArray.get(row).attrName.toLowerCase());
     }
 
-    /** {@inheritDoc} */
+    @Override
     public void setValueAt(Object value, int row, int col)
     {
       dataArray.get(row).value = value;
@@ -634,8 +591,7 @@
       List<Object> ocs = null;
       for (String attrName : searchResult.getAttributeNames())
       {
-        if (attrName.equalsIgnoreCase(
-            ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME))
+        if (ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME.equalsIgnoreCase(attrName))
         {
           if (schema != null)
           {
@@ -666,34 +622,19 @@
             for (AttributeType attr : objectClass.getRequiredAttributeChain())
             {
               String attrName = attr.getNameOrOID();
-              if (!addedAttrs.contains(attrName.toLowerCase()))
+              String lowerCase = attrName.toLowerCase();
+              if (!addedAttrs.contains(lowerCase))
               {
-                if (isBinary(attrName) || isPassword(attrName))
-                {
-                  allSortedValues.add(new AttributeValuePair(attrName,
-                      new byte[]{}));
-                }
-                else
-                {
-                  allSortedValues.add(new AttributeValuePair(attrName, ""));
-                }
+                allSortedValues.add(newAttributeValuePair(attrName));
               }
-              requiredAttrs.add(attrName.toLowerCase());
+              requiredAttrs.add(lowerCase);
             }
             for (AttributeType attr : objectClass.getOptionalAttributeChain())
             {
               String attrName = attr.getNameOrOID();
               if (!addedAttrs.contains(attrName.toLowerCase()))
               {
-                if (isBinary(attrName) || isPassword(attrName))
-                {
-                  allSortedValues.add(new AttributeValuePair(attrName,
-                      new byte[]{}));
-                }
-                else
-                {
-                  allSortedValues.add(new AttributeValuePair(attrName, ""));
-                }
+                allSortedValues.add(newAttributeValuePair(attrName));
               }
             }
           }
@@ -711,12 +652,23 @@
       renderer.setRequiredAttrs(requiredAttrs);
     }
 
+    private AttributeValuePair newAttributeValuePair(String attrName)
+    {
+      if (isBinary(attrName) || isPassword(attrName))
+      {
+        return new AttributeValuePair(attrName, new byte[] {});
+      }
+      else
+      {
+        return new AttributeValuePair(attrName, "");
+      }
+    }
+
     /**
      * Checks if we have to display all the attributes or only those that
      * contain a value and updates the contents of the model accordingly.  Note
      * that even if the required attributes have no value they will be
      * displayed.
-     *
      */
     void updateAttributeVisibility()
     {
@@ -844,11 +796,11 @@
       {
         if (value.value instanceof String)
         {
-          hasValue = ((String)value.value).length() > 0;
+          return ((String) value.value).length() > 0;
         }
         else if (value.value instanceof byte[])
         {
-          hasValue = ((byte[])value.value).length > 0;
+          return ((byte[]) value.value).length > 0;
         }
       }
       return hasValue;
@@ -859,17 +811,12 @@
    * A simple class that contains an attribute name and a single value.  It is
    * used by the table model to be able to retrieve more easily all the values
    * for a given attribute.
-   *
    */
-  class AttributeValuePair
+  static class AttributeValuePair
   {
-    /**
-     * The attribute name.
-     */
+    /** The attribute name. */
     String attrName;
-    /**
-     * The value.
-     */
+    /** The value. */
     Object value;
     /**
      * Constructor.
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/renderer/LDAPEntryTableCellRenderer.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/renderer/LDAPEntryTableCellRenderer.java
index e253086..dea7a95 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/renderer/LDAPEntryTableCellRenderer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/renderer/LDAPEntryTableCellRenderer.java
@@ -12,7 +12,7 @@
  * information: "Portions Copyright [year] [name of copyright owner]".
  *
  * Copyright 2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS.
+ * Portions Copyright 2014-2016 ForgeRock AS.
  */
 package org.opends.guitools.controlpanel.ui.renderer;
 
@@ -36,10 +36,7 @@
 import org.opends.guitools.controlpanel.util.Utilities;
 import org.opends.server.types.Schema;
 
-/**
- * The renderer used by the table in the 'Attribute View' of the LDAP entry
- * browser.
- */
+/** The renderer used by the table in the 'Attribute View' of the LDAP entry browser. */
 public class LDAPEntryTableCellRenderer extends SelectableTableCellRenderer
 {
   private static final long serialVersionUID = 3590456676685339618L;
@@ -51,10 +48,7 @@
   private Schema schema;
   private Collection<String> requiredAttrs = new ArrayList<>();
 
-  /**
-   * Constructor of the cell renderer.
-   *
-   */
+  /** Constructor of the cell renderer. */
   public LDAPEntryTableCellRenderer()
   {
     binaryPanel = new BinaryCellPanel();
@@ -63,10 +57,9 @@
     ocPanel.setOpaque(true);
     GridBagConstraints gbc = new GridBagConstraints();
     add(lockLabel, gbc);
-
   }
 
-  /** {@inheritDoc} */
+  @Override
   public Component getTableCellRendererComponent(JTable table, Object value,
       boolean isSelected, boolean hasFocus, int row, int column) {
     if (isRequired(table, row, column))
@@ -183,16 +176,13 @@
     {
       lockLabel.setIcon(null);
     }
+    else if (column == 1 && !table.isCellEditable(row, column))
+    {
+      lockLabel.setIcon(lockIcon);
+    }
     else
     {
-      if (column == 1 && !table.isCellEditable(row, column))
-      {
-        lockLabel.setIcon(lockIcon);
-      }
-      else
-      {
-        lockLabel.setIcon(null);
-      }
+      lockLabel.setIcon(null);
     }
     return this;
   }

--
Gitblit v1.10.0