mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Gaetan Boismal
10.30.2015 8e398549fb76484e922d6ebfb8519d8dd3c1c2ac
OPENDJ-1932 Code cleanup

* NewBaseDNPanel.java
** validateAutomaticallyGenerated(final Set<LocalizableMessage> errors)
*** Extract local constants
*** Add final keyword

* StatusGenericPanel.java
** checkIntValue(Collection<LocalizableMessage> errors, String stringValue,int minValue, int maxValue, LocalizableMessage errMsg)
*** Now return a boolean to allow client code to use conditionnal code after call
*** Don't throw runtime exception anymore (Thanks Jean-Noël for refactoring advices!)

* ExportLDIFPanel.java
** okClicked()
** Consequences of checkIntValue changes
3 files modified
60 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ExportLDIFPanel.java 13 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java 15 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java 32 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ExportLDIFPanel.java
@@ -377,14 +377,11 @@
    addScheduleErrors(getSchedule(), errors, lExportOptions);
    if (wrapText.isSelected())
    {
      String cols = wrapColumn.getText();
      int minValue = 1;
      int maxValue = 1000;
      LocalizableMessage errMsg = ERR_CTRL_PANEL_INVALID_WRAP_COLUMN.get(minValue,
      maxValue);
      int size1 = errors.size();
      checkIntValue(errors, cols, minValue, maxValue, errMsg);
      if (errors.size() > size1)
      final String cols = wrapColumn.getText();
      final int minValue = 1;
      final int maxValue = 1000;
      final LocalizableMessage errMsg = ERR_CTRL_PANEL_INVALID_WRAP_COLUMN.get(minValue, maxValue);
      if (!checkIntValue(errors, cols, minValue, maxValue, errMsg))
      {
        setPrimaryInvalid(lExportOptions);
      }
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
@@ -118,6 +118,8 @@
 */
public class NewBaseDNPanel extends StatusGenericPanel
{
  private static final int MAX_ENTRIES_NUMBER_GENERATED = 1000;
  private static final int MAX_ENTRIES_NUMBER_GENERATED_LOCAL = 20000;
  private static final long serialVersionUID = -2680821576362341119L;
  private static final LocalizableMessage NEW_BACKEND_TEXT = INFO_CTRL_PANEL_NEW_BACKEND_LABEL.get();
@@ -635,11 +637,14 @@
  {
    if (importAutomaticallyGenerated.isSelected())
    {
      String nEntries = numberOfEntries.getText();
      int minValue = 1;
      int maxValue = isLocal() ? 20000 : 1000;
      LocalizableMessage errMsg = ERR_NUMBER_OF_ENTRIES_INVALID.get(minValue, maxValue);
      checkIntValue(errors, nEntries, minValue, maxValue, errMsg);
      final int minValue = 1;
      final int maxValue = isLocal() ? MAX_ENTRIES_NUMBER_GENERATED_LOCAL
                                     : MAX_ENTRIES_NUMBER_GENERATED;
      final LocalizableMessage errorMsg = ERR_NUMBER_OF_ENTRIES_INVALID.get(minValue, maxValue);
      if (!checkIntValue(errors, numberOfEntries.getText(), minValue, maxValue, errorMsg))
      {
        setSecondaryInvalid(lNumberOfEntries);
      }
    }
  }
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
@@ -1761,28 +1761,36 @@
  /**
   * Checks that the provided string value is a valid integer and if it is not
   * updates a list of error messages with an error.
   * @param errors the list of error messages to be updated.
   * @param stringValue the string value to analyze.
   * @param minValue the minimum integer value accepted.
   * @param maxValue the maximum integer value accepted.
   * @param errMsg the error message to use to update the error list if the
   * provided value is not valid.
   *
   * @param errors
   *          the list of error messages to be updated.
   * @param stringValue
   *          the string value to analyze.
   * @param minValue
   *          the minimum integer value accepted.
   * @param maxValue
   *          the maximum integer value accepted.
   * @param errMsg
   *          the error message to use to update the error list if the provided
   *          value is not valid.
   * @return {@code true} if the provided string value is a valid integer and if
   *         it is not updates a list of error messages with an error.
   */
  protected void checkIntValue(Collection<LocalizableMessage> errors, String stringValue,
  protected boolean checkIntValue(Collection<LocalizableMessage> errors, String stringValue,
      int minValue, int maxValue, LocalizableMessage errMsg)
  {
    try
    {
      int n = Integer.parseInt(stringValue);
      if (n > maxValue || n < minValue)
      if (minValue <= n && n <= maxValue)
      {
        throw new RuntimeException("Invalid value");
        return true;
      }
    }
    catch (Throwable t)
    {
    catch (NumberFormatException ignored) {}
      errors.add(errMsg);
    }
    return false;
  }
  /**