From 49c8560679d3e0217f34ed017d2382ec43e4f300 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 05 Jul 2016 12:57:45 +0000
Subject: [PATCH] Inlined useless methods from InstallerHelper

---
 opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java |   40 +++++-----
 opendj-server-legacy/src/main/java/org/opends/server/backends/task/TaskState.java                |   86 +++++++--------------
 opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java                |   19 ++--
 opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java          |   56 --------------
 4 files changed, 60 insertions(+), 141 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
index 83416a3..1d8449c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/Installer.java
@@ -30,6 +30,7 @@
 import static org.opends.quicksetup.installer.DataReplicationOptions.Type.*;
 import static org.opends.quicksetup.installer.InstallProgressStep.*;
 import static org.opends.quicksetup.util.Utils.*;
+import static org.opends.server.backends.task.TaskState.*;
 
 import java.awt.event.WindowEvent;
 import java.io.BufferedWriter;
@@ -123,6 +124,7 @@
 import org.opends.quicksetup.util.IncompatibleVersionException;
 import org.opends.quicksetup.util.ServerController;
 import org.opends.quicksetup.util.Utils;
+import org.opends.server.backends.task.TaskState;
 import org.opends.server.tools.BackendTypeHelper;
 import org.opends.server.tools.BackendTypeHelper.BackendTypeUIAdapter;
 import org.opends.server.types.HostPort;
@@ -4334,8 +4336,9 @@
         }
         InstallerHelper helper = new InstallerHelper();
         String state = getFirstValue(sr, "ds-task-state");
+        TaskState taskState = TaskState.fromString(state);
 
-        if (helper.isDone(state) || helper.isStoppedByError(state))
+        if (TaskState.isDone(taskState) || taskState == STOPPED_BY_ERROR)
         {
           isOver = true;
           LocalizableMessage errorMsg;
@@ -4358,14 +4361,14 @@
           }
 
           logger.warn(LocalizableMessage.raw("Processed errorMsg: " + errorMsg));
-          if (helper.isCompletedWithErrors(state))
+          if (taskState == COMPLETED_WITH_ERRORS)
           {
             if (displayProgress)
             {
               notifyListeners(getFormattedWarning(errorMsg));
             }
           }
-          else if (!helper.isSuccessful(state) || helper.isStoppedByError(state))
+          else if (!TaskState.isSuccessful(taskState) || taskState == STOPPED_BY_ERROR)
           {
             ApplicationException ae = new ApplicationException(ReturnCode.APPLICATION_ERROR, errorMsg, null);
             if (lastLogMsg == null || helper.isPeersNotFoundError(lastLogMsg))
@@ -4493,22 +4496,22 @@
           logger.info(LocalizableMessage.raw(logMsg));
           lastLogMsg = logMsg;
         }
-        InstallerHelper helper = new InstallerHelper();
-        String state = getFirstValue(sr, "ds-task-state");
 
-        if (helper.isDone(state) || helper.isStoppedByError(state))
+        String state = getFirstValue(sr, "ds-task-state");
+        TaskState taskState = TaskState.fromString(state);
+        if (TaskState.isDone(taskState) || taskState == STOPPED_BY_ERROR)
         {
           isOver = true;
           LocalizableMessage errorMsg = lastLogMsg != null ?
               INFO_ERROR_DURING_INITIALIZATION_LOG.get(sourceServerDisplay, lastLogMsg, state, sourceServerDisplay)
             : INFO_ERROR_DURING_INITIALIZATION_NO_LOG.get(sourceServerDisplay, state, sourceServerDisplay);
 
-          if (helper.isCompletedWithErrors(state))
+          if (taskState == COMPLETED_WITH_ERRORS)
           {
             logger.warn(LocalizableMessage.raw("Completed with error: " + errorMsg));
             notifyListeners(getFormattedWarning(errorMsg));
           }
-          else if (!helper.isSuccessful(state) || helper.isStoppedByError(state))
+          else if (!TaskState.isSuccessful(taskState) || taskState == STOPPED_BY_ERROR)
           {
             logger.warn(LocalizableMessage.raw("Error: " + errorMsg));
             throw new ApplicationException(ReturnCode.APPLICATION_ERROR, errorMsg, null);
diff --git a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
index 54c3c2b..e880fb4 100644
--- a/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/quicksetup/installer/InstallerHelper.java
@@ -75,7 +75,6 @@
 import org.opends.quicksetup.UserData;
 import org.opends.quicksetup.util.OutputReader;
 import org.opends.quicksetup.util.Utils;
-import org.opends.server.backends.task.TaskState;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.tools.ConfigureDS;
 import org.opends.server.tools.ConfigureWindowsService;
@@ -687,61 +686,6 @@
   }
 
   /**
-   * For the given state provided by a Task tells if the task is done or not.
-   *
-   * @param sState
-   *          the String representing the task state.
-   * @return <CODE>true</CODE> if the task is done and <CODE>false</CODE>
-   *         otherwise.
-   */
-  public boolean isDone(String sState)
-  {
-    return TaskState.isDone(TaskState.fromString(sState));
-  }
-
-  /**
-   * For the given state provided by a Task tells if the task is successful or
-   * not.
-   *
-   * @param sState
-   *          the String representing the task state.
-   * @return <CODE>true</CODE> if the task is successful and <CODE>false</CODE>
-   *         otherwise.
-   */
-  public boolean isSuccessful(String sState)
-  {
-    return TaskState.isSuccessful(TaskState.fromString(sState));
-  }
-
-  /**
-   * For the given state provided by a Task tells if the task is complete with
-   * errors or not.
-   *
-   * @param sState
-   *          the String representing the task state.
-   * @return <CODE>true</CODE> if the task is complete with errors and
-   *         <CODE>false</CODE> otherwise.
-   */
-  public boolean isCompletedWithErrors(String sState)
-  {
-    return TaskState.COMPLETED_WITH_ERRORS == TaskState.fromString(sState);
-  }
-
-  /**
-   * For the given state provided by a Task tells if the task is stopped by
-   * error or not.
-   *
-   * @param sState
-   *          the String representing the task state.
-   * @return <CODE>true</CODE> if the task is stopped by error and
-   *         <CODE>false</CODE> otherwise.
-   */
-  public boolean isStoppedByError(String sState)
-  {
-    return TaskState.STOPPED_BY_ERROR == TaskState.fromString(sState);
-  }
-
-  /**
    * Tells whether the provided log message corresponds to a peers not found
    * error during the initialization of a replica or not.
    *
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/task/TaskState.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/task/TaskState.java
index cac6651..498ef14 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/task/TaskState.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/task/TaskState.java
@@ -16,14 +16,11 @@
  */
 package org.opends.server.backends.task;
 
-import org.forgerock.i18n.LocalizableMessage;
 import static org.opends.messages.TaskMessages.*;
 
+import org.forgerock.i18n.LocalizableMessage;
 
-/**
- * This enumeration defines the various states that a task can have during its
- * lifetime.
- */
+/** This enumeration defines the various states that a task can have during its lifetime. */
 public enum TaskState
 {
   /**
@@ -130,8 +127,8 @@
    *
    * @param  taskState  The task state for which to make the determination.
    *
-   * @return  <CODE>true</CODE> if the stask tate indicates that the task is
-   *          currently pending, or <CODE>false</CODE> otherwise.
+   * @return  {@code true} if the task state indicates that the task is
+   *          currently pending, or {@code false} otherwise.
    */
   public static boolean isPending(TaskState taskState)
   {
@@ -153,8 +150,8 @@
    *
    * @param  taskState  The task state for which to make the determination.
    *
-   * @return  <CODE>true</CODE> if the task state indicates that the task is
-   *          currently running, or <CODE>false</CODE> otherwise.
+   * @return  {@code true} if the task state indicates that the task is
+   *          currently running, or {@code false} otherwise.
    */
   public static boolean isRunning(TaskState taskState)
   {
@@ -174,8 +171,8 @@
    *
    * @param  taskState  The task state for which to make the determination.
    *
-   * @return  <CODE>true</CODE> if the task state indicates that the task
-   *          is recurring, or <CODE>false</CODE> otherwise.
+   * @return  {@code true} if the task state indicates that the task
+   *          is recurring, or {@code false} otherwise.
    */
   public static boolean isRecurring(TaskState taskState)
   {
@@ -197,9 +194,8 @@
    *
    * @param  taskState  The task state for which to make the determination.
    *
-   * @return  <CODE>false</CODE> if the task state indicates that the task has
-   *          not yet started or is currently running, or <CODE>true</CODE>
-   *          otherwise.
+   * @return  {@code false} if the task state indicates that the task has
+   *          not yet started or is currently running, or {@code true} otherwise
    */
   public static boolean isDone(TaskState taskState)
   {
@@ -223,9 +219,9 @@
    *
    * @param  taskState  The task state for which to make the determination.
    *
-   * @return  <CODE>true</CODE> if the task state indicates that the task
+   * @return  {@code true} if the task state indicates that the task
    *          completed successfully or with minor errors that still allowed it
-   *          to achieve its goal, or <CODE>false</CODE> otherwise.
+   *          to achieve its goal, or {@code false} otherwise.
    */
   public static boolean isSuccessful(TaskState taskState)
   {
@@ -248,9 +244,9 @@
    *
    * @param  taskState  The task state for which to make the determination.
    *
-   * @return  <CODE>true</CODE> if the task state indicates that the task
+   * @return  {@code true} if the task state indicates that the task
    *          was cancelled either before or during execution, or
-   *          <CODE>false</CODE> otherwise.
+   *          {@code false} otherwise.
    */
   public static boolean isCancelled(TaskState taskState)
   {
@@ -270,62 +266,38 @@
    * @param  s  The string value for which to retrieve the corresponding task
    *            state.
    *
-   * @return  The corresponding task state, or <CODE>null</CODE> if none could
+   * @return  The corresponding task state, or {@code null} if none could
    *          be associated with the provided string.
    */
   public static TaskState fromString(String s)
   {
-    String lowerString = s.toLowerCase();
-    if (lowerString.equals("unscheduled"))
+    switch (s.toLowerCase())
     {
+    case "unscheduled":
       return UNSCHEDULED;
-    }
-    else if (lowerString.equals("disabled"))
-    {
+    case "disabled":
       return DISABLED;
-    }
-    else if (lowerString.equals("waiting_on_start_time"))
-    {
+    case "waiting_on_start_time":
       return WAITING_ON_START_TIME;
-    }
-    else if (lowerString.equals("waiting_on_dependency"))
-    {
+    case "waiting_on_dependency":
       return WAITING_ON_DEPENDENCY;
-    }
-    else if (lowerString.equals("running"))
-    {
+    case "running":
       return RUNNING;
-    }
-    else if (lowerString.equals("recurring"))
-    {
+    case "recurring":
       return RECURRING;
-    }
-    else if (lowerString.equals("completed_successfully"))
-    {
+    case "completed_successfully":
       return COMPLETED_SUCCESSFULLY;
-    }
-    else if (lowerString.equals("completed_with_errors"))
-    {
+    case "completed_with_errors":
       return COMPLETED_WITH_ERRORS;
-    }
-    else if (lowerString.equals("stopped_by_shutdown"))
-    {
+    case "stopped_by_shutdown":
       return STOPPED_BY_SHUTDOWN;
-    }
-    else if (lowerString.equals("stopped_by_error"))
-    {
+    case "stopped_by_error":
       return STOPPED_BY_ERROR;
-    }
-    else if (lowerString.equals("stopped_by_administrator"))
-    {
+    case "stopped_by_administrator":
       return STOPPED_BY_ADMINISTRATOR;
-    }
-    else if (lowerString.equals("canceled_before_starting"))
-    {
+    case "canceled_before_starting":
       return CANCELED_BEFORE_STARTING;
-    }
-    else
-    {
+    default:
       return null;
     }
   }
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
index ac4acf9..71bffc5 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliMain.java
@@ -32,6 +32,7 @@
 import static org.opends.messages.QuickSetupMessages.*;
 import static org.opends.messages.ToolMessages.*;
 import static org.opends.quicksetup.util.Utils.*;
+import static org.opends.server.backends.task.TaskState.*;
 import static org.opends.server.tools.dsreplication.ReplicationCliArgumentParser.*;
 import static org.opends.server.tools.dsreplication.ReplicationCliReturnCode.*;
 import static org.opends.server.util.StaticUtils.*;
@@ -131,6 +132,7 @@
 import org.opends.quicksetup.installer.InstallerHelper;
 import org.opends.quicksetup.installer.PeerNotFoundException;
 import org.opends.quicksetup.util.PlainTextProgressMessageFormatter;
+import org.opends.server.backends.task.TaskState;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.loggers.JDKLogging;
 import org.opends.server.tasks.PurgeConflictsHistoricalTask;
@@ -1440,18 +1442,18 @@
           logger.info(LocalizableMessage.raw(logMsg));
           lastLogMsg = logMsg;
         }
-        InstallerHelper helper = new InstallerHelper();
-        String state = getFirstValue(sr, "ds-task-state");
 
-        if (helper.isDone(state) || helper.isStoppedByError(state))
+        String state = getFirstValue(sr, "ds-task-state");
+        TaskState taskState = TaskState.fromString(state);
+        if (TaskState.isDone(taskState) || taskState == STOPPED_BY_ERROR)
         {
           LocalizableMessage errorMsg = ERR_UNEXPECTED_DURING_TASK_WITH_LOG.get(lastLogMsg, state, conn.getHostPort());
-          if (helper.isCompletedWithErrors(state))
+          if (taskState == COMPLETED_WITH_ERRORS)
           {
             logger.warn(LocalizableMessage.raw("Completed with error: " + errorMsg));
             errPrintln(errorMsg);
           }
-          else if (!helper.isSuccessful(state) || helper.isStoppedByError(state))
+          else if (!TaskState.isSuccessful(taskState) || taskState == STOPPED_BY_ERROR)
           {
             logger.warn(LocalizableMessage.raw("Error: " + errorMsg));
             throw new ReplicationCliException(errorMsg, ERROR_LAUNCHING_RESET_CHANGE_NUMBER, null);
@@ -1589,21 +1591,20 @@
           logger.info(LocalizableMessage.raw(logMsg));
           lastLogMsg = logMsg;
         }
-        InstallerHelper helper = new InstallerHelper();
-        String state = getFirstValue(sr, "ds-task-state");
 
-        if (helper.isDone(state) || helper.isStoppedByError(state))
+        String state = getFirstValue(sr, "ds-task-state");
+        TaskState taskState = TaskState.fromString(state);
+        if (TaskState.isDone(taskState) || taskState == STOPPED_BY_ERROR)
         {
           isOver = true;
           LocalizableMessage errorMsg = getPurgeErrorMsg(lastLogMsg, state, conn);
 
-          if (helper.isCompletedWithErrors(state))
+          if (taskState == COMPLETED_WITH_ERRORS)
           {
             logger.warn(LocalizableMessage.raw("Completed with error: "+errorMsg));
             errPrintln(errorMsg);
           }
-          else if (!helper.isSuccessful(state) ||
-              helper.isStoppedByError(state))
+          else if (!TaskState.isSuccessful(taskState) || taskState == STOPPED_BY_ERROR)
           {
             logger.warn(LocalizableMessage.raw("Error: "+errorMsg));
             ReplicationCliReturnCode code = ERROR_LAUNCHING_PURGE_HISTORICAL;
@@ -7156,21 +7157,20 @@
           logger.info(LocalizableMessage.raw(logMsg));
           lastLogMsg = logMsg;
         }
-        InstallerHelper helper = new InstallerHelper();
         String state = getFirstValue(sr, "ds-task-state");
+        TaskState taskState = TaskState.fromString(state);
 
-        if (helper.isDone(state) || helper.isStoppedByError(state))
+        if (TaskState.isDone(taskState) || taskState == STOPPED_BY_ERROR)
         {
           isOver = true;
           LocalizableMessage errorMsg = getPrePostErrorMsg(lastLogMsg, state, conn);
 
-          if (helper.isCompletedWithErrors(state))
+          if (TaskState.COMPLETED_WITH_ERRORS == taskState)
           {
             logger.warn(LocalizableMessage.raw("Completed with error: "+errorMsg));
             errPrintln(errorMsg);
           }
-          else if (!helper.isSuccessful(state) ||
-              helper.isStoppedByError(state))
+          else if (!TaskState.isSuccessful(taskState) || taskState == STOPPED_BY_ERROR)
           {
             logger.warn(LocalizableMessage.raw("Error: "+errorMsg));
             ReplicationCliReturnCode code = isPre?
@@ -7305,8 +7305,9 @@
         }
         InstallerHelper helper = new InstallerHelper();
         String state = getFirstValue(sr, "ds-task-state");
+        TaskState taskState = TaskState.fromString(state);
 
-        if (helper.isDone(state) || helper.isStoppedByError(state))
+        if (TaskState.isDone(taskState) || taskState == STOPPED_BY_ERROR)
         {
           isOver = true;
           logger.info(LocalizableMessage.raw("Last task entry: "+sr));
@@ -7318,7 +7319,7 @@
           }
 
           LocalizableMessage errorMsg = getInitializeAllErrorMsg(hostPort, lastLogMsg, state);
-          if (helper.isCompletedWithErrors(state))
+          if (TaskState.COMPLETED_WITH_ERRORS == taskState)
           {
             logger.warn(LocalizableMessage.raw("Processed errorMsg: "+errorMsg));
             if (displayProgress)
@@ -7326,8 +7327,7 @@
               errPrintln(errorMsg);
             }
           }
-          else if (!helper.isSuccessful(state) ||
-              helper.isStoppedByError(state))
+          else if (!TaskState.isSuccessful(taskState) || taskState == STOPPED_BY_ERROR)
           {
             logger.warn(LocalizableMessage.raw("Processed errorMsg: "+errorMsg));
             ClientException ce = new ClientException(

--
Gitblit v1.10.0