From 540b3383603143e20d40d93ef44fbb9d132c283c Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 22 Apr 2015 12:51:56 +0000
Subject: [PATCH] Code cleanup
---
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java | 84 ++++++++------------
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java | 112 ++++++++++++++-------------
2 files changed, 92 insertions(+), 104 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java
index ae4d3fd..8103b3e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java
@@ -24,7 +24,6 @@
* Copyright 2008-2010 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
-
package org.opends.guitools.controlpanel.ui;
import static org.opends.messages.AdminToolMessages.*;
@@ -46,11 +45,11 @@
import javax.swing.JTextField;
import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.opendj.server.config.meta.LocalDBIndexCfgDefn;
import org.opends.guitools.controlpanel.datamodel.IndexTypeDescriptor;
import org.opends.guitools.controlpanel.ui.components.TitlePanel;
import org.opends.guitools.controlpanel.ui.renderer.CustomListCellRenderer;
import org.opends.guitools.controlpanel.util.Utilities;
-import org.opends.server.admin.std.meta.LocalDBIndexCfgDefn;
import org.opends.server.types.AttributeType;
/**
@@ -62,82 +61,69 @@
private static final long serialVersionUID = 4465529396749593707L;
/** Custom attributes message. */
- static LocalizableMessage CUSTOM_ATTRIBUTES = INFO_CTRL_PANEL_CUSTOM_ATTRIBUTES_LABEL.get();
-
+ static final LocalizableMessage CUSTOM_ATTRIBUTES = INFO_CTRL_PANEL_CUSTOM_ATTRIBUTES_LABEL.get();
/** Standard attributes message. */
- static LocalizableMessage STANDARD_ATTRIBUTES = INFO_CTRL_PANEL_STANDARD_ATTRIBUTES_LABEL.get();
+ static final LocalizableMessage STANDARD_ATTRIBUTES = INFO_CTRL_PANEL_STANDARD_ATTRIBUTES_LABEL.get();
/** Minimum value for entry limit. */
static final int MIN_ENTRY_LIMIT =
LocalDBIndexCfgDefn.getInstance().getIndexEntryLimitPropertyDefinition().getLowerLimit();
-
/** Maximum value for entry limit. */
static final int MAX_ENTRY_LIMIT =
LocalDBIndexCfgDefn.getInstance().getIndexEntryLimitPropertyDefinition().getUpperLimit();
/** LocalizableMessage to be displayed to indicate that an index is not configurable. */
- static LocalizableMessage NON_CONFIGURABLE_INDEX = INFO_CTRL_PANEL_NON_CONFIGURABLE_INDEX_LABEL.get();
-
+ static final LocalizableMessage NON_CONFIGURABLE_INDEX = INFO_CTRL_PANEL_NON_CONFIGURABLE_INDEX_LABEL.get();
/** LocalizableMessage to be displayed to indicate that an index has been modified. */
- static LocalizableMessage INDEX_MODIFIED = INFO_CTRL_PANEL_INDEX_MODIFIED_LABEL.get();
+ static final LocalizableMessage INDEX_MODIFIED = INFO_CTRL_PANEL_INDEX_MODIFIED_LABEL.get();
/** Default value for entry limit. */
static final int DEFAULT_ENTRY_LIMIT = 4000;
- TitlePanel titlePanel = new TitlePanel(LocalizableMessage.EMPTY, LocalizableMessage.EMPTY);
+ final TitlePanel titlePanel = new TitlePanel(LocalizableMessage.EMPTY, LocalizableMessage.EMPTY);
/** Attributes combo box. */
- JComboBox attributes = Utilities.createComboBox();
+ final JComboBox attributes = Utilities.createComboBox();
/** Name of the index label. */
- JLabel name = Utilities.createDefaultLabel();
+ final JLabel name = Utilities.createDefaultLabel();
/** Backends label. */
- JLabel lBackend = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_BACKEND_LABEL.get());
-
+ final JLabel lBackend = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_BACKEND_LABEL.get());
/** Read-only backend name label. */
- JLabel backendName = Utilities.createDefaultLabel();
+ final JLabel backendName = Utilities.createDefaultLabel();
- JLabel lAttribute = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ATTRIBUTE_LABEL.get());
+ final JLabel lAttribute = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ATTRIBUTE_LABEL.get());
- JLabel lEntryLimit = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ENTRY_LIMIT_LABEL.get());
+ final JLabel lEntryLimit = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_ENTRY_LIMIT_LABEL.get());
- JTextField entryLimit = Utilities.createShortTextField();
+ final JTextField entryLimit = Utilities.createShortTextField();
- JLabel lType = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_INDEX_TYPE_LABEL.get());
+ final JLabel lType = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_INDEX_TYPE_LABEL.get());
+ /** Panel containing all the index types. */
+ final JPanel typesPanel = new JPanel(new GridBagLayout());
/** Approximate index type check box. */
- JCheckBox approximate = Utilities.createCheckBox(INFO_CTRL_PANEL_APPROXIMATE_LABEL.get());
-
+ final JCheckBox approximate = Utilities.createCheckBox(INFO_CTRL_PANEL_APPROXIMATE_LABEL.get());
/** Equality index type check box. */
- JCheckBox equality = Utilities.createCheckBox(INFO_CTRL_PANEL_EQUALITY_LABEL.get());
-
+ final JCheckBox equality = Utilities.createCheckBox(INFO_CTRL_PANEL_EQUALITY_LABEL.get());
/** Ordering index type check box. */
- JCheckBox ordering = Utilities.createCheckBox(INFO_CTRL_PANEL_ORDERING_LABEL.get());
-
+ final JCheckBox ordering = Utilities.createCheckBox(INFO_CTRL_PANEL_ORDERING_LABEL.get());
/** Presence index type check box. */
- JCheckBox presence = Utilities.createCheckBox(INFO_CTRL_PANEL_PRESENCE_LABEL.get());
-
+ final JCheckBox presence = Utilities.createCheckBox(INFO_CTRL_PANEL_PRESENCE_LABEL.get());
/** Substring index type check box. */
- JCheckBox substring = Utilities.createCheckBox(INFO_CTRL_PANEL_SUBSTRING_LABEL.get());
+ final JCheckBox substring = Utilities.createCheckBox(INFO_CTRL_PANEL_SUBSTRING_LABEL.get());
+ /** Array of checkboxes. */
+ final JCheckBox[] types = { approximate, equality, ordering, presence, substring };
+ /** Array of index types that matches the array of checkboxes (types). */
+ final IndexTypeDescriptor[] configTypes = { IndexTypeDescriptor.APPROXIMATE, IndexTypeDescriptor.EQUALITY,
+ IndexTypeDescriptor.ORDERING, IndexTypeDescriptor.PRESENCE, IndexTypeDescriptor.SUBSTRING };
- JButton deleteIndex = Utilities.createButton(INFO_CTRL_PANEL_DELETE_INDEX_LABEL.get());
-
- JButton saveChanges = Utilities.createButton(INFO_CTRL_PANEL_SAVE_CHANGES_LABEL.get());
+ final JButton deleteIndex = Utilities.createButton(INFO_CTRL_PANEL_DELETE_INDEX_LABEL.get());
+ final JButton saveChanges = Utilities.createButton(INFO_CTRL_PANEL_SAVE_CHANGES_LABEL.get());
/** Label containing some warning information (such as the fact that the index cannot be edited). */
- JLabel warning = Utilities.createDefaultLabel();
-
- /** Panel containing all the index types. */
- JPanel typesPanel = new JPanel(new GridBagLayout());
-
- /** Array of checkboxes. */
- JCheckBox[] types = { approximate, equality, ordering, presence, substring };
-
- /** Array of index types that matches the array of checkboxes (types). */
- IndexTypeDescriptor[] configTypes = { IndexTypeDescriptor.APPROXIMATE, IndexTypeDescriptor.EQUALITY,
- IndexTypeDescriptor.ORDERING, IndexTypeDescriptor.PRESENCE,
- IndexTypeDescriptor.SUBSTRING };
+ final JLabel warning = Utilities.createDefaultLabel();
/**
* Repopulates the contents of the panel with the provided attribute type. It
@@ -294,10 +280,10 @@
gbc.gridy++;
gbc2 = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
- for (int i = 0; i < types.length; i++)
+ for (JCheckBox type : types)
{
- types[i].setOpaque(false);
- typesPanel.add(types[i], gbc2);
+ type.setOpaque(false);
+ typesPanel.add(type, gbc2);
gbc2.anchor = GridBagConstraints.WEST;
gbc2.insets.top = 10;
}
@@ -318,7 +304,7 @@
*/
SortedSet<IndexTypeDescriptor> getTypes()
{
- SortedSet<IndexTypeDescriptor> indexTypes = new TreeSet<IndexTypeDescriptor>();
+ SortedSet<IndexTypeDescriptor> indexTypes = new TreeSet<>();
for (int i = 0; i < types.length; i++)
{
if (types[i].isSelected())
@@ -338,7 +324,7 @@
*/
List<LocalizableMessage> getErrors()
{
- List<LocalizableMessage> errors = new ArrayList<LocalizableMessage>();
+ List<LocalizableMessage> errors = new ArrayList<>();
setPrimaryValid(lEntryLimit);
setPrimaryValid(lType);
@@ -347,7 +333,7 @@
try
{
int n = Integer.parseInt(newEntryLimit);
- if (n < MIN_ENTRY_LIMIT || n > MAX_ENTRY_LIMIT)
+ if (n < MIN_ENTRY_LIMIT || MAX_ENTRY_LIMIT < n)
{
errors.add(ERR_CTRL_PANEL_INVALID_ENTRY_LIMIT_LABEL.get(MIN_ENTRY_LIMIT, MAX_ENTRY_LIMIT));
setPrimaryInvalid(lEntryLimit);
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
index da526cf..af332a2 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
@@ -24,7 +24,6 @@
* Copyright 2008-2009 Sun Microsystems, Inc.
* Portions Copyright 2014-2015 ForgeRock AS
*/
-
package org.opends.guitools.controlpanel.ui;
import static org.opends.messages.AdminToolMessages.*;
@@ -38,7 +37,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -88,9 +86,7 @@
private static final long serialVersionUID = -3516011638125862137L;
private final Component relativeComponent;
-
private Schema schema;
-
private IndexDescriptor newIndex;
/**
@@ -145,38 +141,17 @@
{
schema = s;
repack[0] = attributes.getItemCount() == 0;
- LinkedHashSet<CategorizedComboBoxElement> newElements = new LinkedHashSet<CategorizedComboBoxElement>();
+ LinkedHashSet<CategorizedComboBoxElement> newElements = new LinkedHashSet<>();
- // Check that the index does not exist
- BackendDescriptor backend = null;
- for (BackendDescriptor b : getInfo().getServerDescriptor().getBackends())
- {
- if (b.getBackendID().equalsIgnoreCase(backendName.getText()))
- {
- backend = b;
- break;
- }
- }
+ BackendDescriptor backend = getBackendByID(backendName.getText());
- TreeSet<String> standardAttrNames = new TreeSet<String>();
- TreeSet<String> configurationAttrNames = new TreeSet<String>();
- TreeSet<String> customAttrNames = new TreeSet<String>();
+ TreeSet<String> standardAttrNames = new TreeSet<>();
+ TreeSet<String> configurationAttrNames = new TreeSet<>();
+ TreeSet<String> customAttrNames = new TreeSet<>();
for (AttributeType attr : schema.getAttributeTypes().values())
{
String name = attr.getPrimaryName();
- boolean defined = false;
- if (backend != null)
- {
- for (IndexDescriptor index : backend.getIndexes())
- {
- if (index.getName().equalsIgnoreCase(name))
- {
- defined = true;
- break;
- }
- }
- }
- if (!defined)
+ if (!indexExists(backend, name))
{
if (Utilities.isStandard(attr))
{
@@ -244,13 +219,40 @@
}
}
+ private boolean indexExists(BackendDescriptor backend, String indexName)
+ {
+ if (backend != null)
+ {
+ for (IndexDescriptor index : backend.getIndexes())
+ {
+ if (index.getName().equalsIgnoreCase(indexName))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private BackendDescriptor getBackendByID(String backendID)
+ {
+ for (BackendDescriptor b : getInfo().getServerDescriptor().getBackends())
+ {
+ if (b.getBackendID().equalsIgnoreCase(backendID))
+ {
+ return b;
+ }
+ }
+ return null;
+ }
+
@Override
public void okClicked()
{
setPrimaryValid(lAttribute);
setPrimaryValid(lEntryLimit);
setPrimaryValid(lType);
- List<LocalizableMessage> errors = new ArrayList<LocalizableMessage>();
+ List<LocalizableMessage> errors = new ArrayList<>();
String attrName = getAttributeName();
if (attrName == null)
{
@@ -262,7 +264,7 @@
try
{
int n = Integer.parseInt(v);
- if (n < MIN_ENTRY_LIMIT || n > MAX_ENTRY_LIMIT)
+ if (n < MIN_ENTRY_LIMIT || MAX_ENTRY_LIMIT < n)
{
errors.add(ERR_INFO_CTRL_PANEL_ENTRY_LIMIT_NOT_VALID.get(MIN_ENTRY_LIMIT, MAX_ENTRY_LIMIT));
setPrimaryInvalid(lEntryLimit);
@@ -274,16 +276,7 @@
setPrimaryInvalid(lEntryLimit);
}
- boolean somethingSelected = false;
- for (JCheckBox type : types)
- {
- somethingSelected = type.isSelected() && type.isVisible();
- if (somethingSelected)
- {
- break;
- }
- }
- if (!somethingSelected)
+ if (!isSomethingSelected())
{
errors.add(ERR_INFO_ONE_INDEX_TYPE_MUST_BE_SELECTED.get());
setPrimaryInvalid(lType);
@@ -312,6 +305,19 @@
}
}
+ private boolean isSomethingSelected()
+ {
+ for (JCheckBox type : types)
+ {
+ boolean somethingSelected = type.isSelected() && type.isVisible();
+ if (somethingSelected)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
private String getAttributeName()
{
CategorizedComboBoxElement o = (CategorizedComboBoxElement) attributes.getSelectedItem();
@@ -344,7 +350,7 @@
/** The task in charge of creating the index. */
private class NewIndexTask extends Task
{
- private final Set<String> backendSet;
+ private final Set<String> backendSet = new HashSet<>();
private final String attributeName;
private final int entryLimitValue;
private final SortedSet<IndexTypeDescriptor> indexTypes;
@@ -360,7 +366,6 @@
public NewIndexTask(final ControlPanelInfo info, final ProgressDialog dlg)
{
super(info, dlg);
- backendSet = new HashSet<String>();
backendSet.add(backendName.getText());
attributeName = getAttributeName();
entryLimitValue = Integer.parseInt(entryLimit.getText());
@@ -482,7 +487,7 @@
private String getIndexLDIF()
{
String dn = Utilities.getRDNString("ds-cfg-backend-id", backendName.getText()) + ",cn=Backends,cn=config";
- ArrayList<String> lines = new ArrayList<String>();
+ ArrayList<String> lines = new ArrayList<>();
lines.add("dn: " + Utilities.getRDNString("ds-cfg-attribute", attributeName) + ",cn=Index," + dn);
lines.add("objectClass: ds-cfg-local-db-index");
lines.add("objectClass: top");
@@ -544,10 +549,9 @@
Attributes attrs = new BasicAttributes();
BasicAttribute oc = new BasicAttribute("objectClass");
- Iterator<ByteString> it = indexEntry.getObjectClassAttribute().iterator();
- while (it.hasNext())
+ for (ByteString bs : indexEntry.getObjectClassAttribute())
{
- oc.add(it.next().toString());
+ oc.add(bs.toString());
}
attrs.put(oc);
@@ -556,10 +560,9 @@
{
String attrName = odsAttr.getName();
BasicAttribute attr = new BasicAttribute(attrName);
- it = odsAttr.iterator();
- while (it.hasNext())
+ for (ByteString bs : odsAttr)
{
- attr.add(it.next().toString());
+ attr.add(bs.toString());
}
attrs.put(attr);
}
@@ -596,7 +599,7 @@
@Override
protected List<String> getCommandLineArguments()
{
- return new ArrayList<String>();
+ return new ArrayList<>();
}
private String getConfigCommandLineName()
@@ -605,7 +608,6 @@
{
return getCommandLinePath("dsconfig");
}
-
return null;
}
@@ -649,7 +651,7 @@
private ArrayList<String> getDSConfigCommandLineArguments()
{
- ArrayList<String> args = new ArrayList<String>();
+ ArrayList<String> args = new ArrayList<>();
args.add("create-local-db-index");
args.add("--backend-name");
args.add(backendName.getText());
--
Gitblit v1.10.0