org.cpsolver.ifs.util

## Class Progress

- java.lang.Object
- - org.cpsolver.ifs.util.Progress

-     public class Progress
      extends Object

  Progress bar.
  Single instance class for recording the current state. It also allows recursive storing/restoring of the progress.
  Use:

       Progress.getInstance().setStatus("Loading input data");
       Progress.getInstance().setPhase("Creating variables ...", nrVariables);
       for (int i=0;i<nrVariables;i++) {
           //load variable here
           Progress.getInstance().incProgress();
       }
       Progress.getInstance().setPhase("Creating constraints ...", nrConstraints);
       for (int i=0;i<nrConstraints;i++) {
           //load constraint here
           Progress.getInstance().incProgress();
       }
       Progress.getInstance().setStatus("Solving problem");
       ...

  Version:
    IFS 1.3 (Iterative Forward Search)
    Copyright (C) 2006 - 2014 Tomáš Müller
    muller@unitime.org
    http://muller.unitime.org
    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public License along with this library; if not see http://www.gnu.org/licenses/.
  Author:
    Tomáš Müller

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Progress.Message` Log nessage

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `MSGLEVEL_DEBUG`
    `static int` | `MSGLEVEL_ERROR`
    `static int` | `MSGLEVEL_FATAL`
    `static int` | `MSGLEVEL_INFO`
    `static int` | `MSGLEVEL_PROGRESS`
    `static int` | `MSGLEVEL_STAGE`
    `static int` | `MSGLEVEL_TRACE`
    `static int` | `MSGLEVEL_WARN`
    `static SimpleDateFormat` | `sDF`
    `static boolean` | `sTraceEnabled`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addProgressListener(ProgressListener listener)` Adds progress listener
    `static void` | `changeInstance(Object oldKey, Object newKey)` Change progress instance for the given key
    `void` | `clear()` Clear the log
    `void` | `clearProgressListeners()` Remove all progress listeners
    `void` | `debug(String message)` Prints a debug message
    `void` | `debug(String message, Throwable e)` Prints a debug message
    `void` | `error(String message)` Prints an error message
    `void` | `error(String message, Throwable e)` Prints an error message
    `void` | `fatal(String message)` Prints a fatal message
    `void` | `fatal(String message, Throwable e)` Prints a fatal message
    `String` | `getHtmlLog(int level, boolean includeDate)` Returns log in HTML format
    `String` | `getHtmlLog(int level, boolean includeDate, String fromStage)` Returns log in HTML format (only messages with the given level or higher are included)
    `static Progress` | `getInstance()` Progress default instance
    `static Progress` | `getInstance(Object key)` Progress instance
    `List<Progress.Message>` | `getLog()` Returns log (list of messages)
    `String` | `getLog(int level)` Returns log (list of messages).
    `String` | `getPhase()` Current phase
    `long` | `getProgress()` Current progress
    `long` | `getProgressMax()` Maximum of current progress
    `String` | `getStatus()` Current status
    `void` | `incProgress()` Increment current progress
    `void` | `info(String message)` Prints an info message
    `void` | `info(String message, Throwable e)` Prints an info message
    `void` | `load(Element root, boolean clear)` Restores the message log from the given XML element
    `void` | `message(int level, String message)` Prints a message
    `void` | `message(int level, String message, Throwable t)` Prints a message
    `static void` | `removeInstance(Object key)` Remove progress instance for the given key
    `void` | `removeProgressListener(ProgressListener listener)` Remove progress listener
    `void` | `restore()` Resore the progress from the heap memory
    `void` | `save()` Save current progress to the heap memory
    `void` | `save(Element root)` Saves the message log into the given XML element
    `void` | `setPhase(String phase)` Sets current phase.
    `void` | `setPhase(String phase, long progressMax)` Sets current phase
    `void` | `setProgress(long progress)` Update progress bar.
    `void` | `setStatus(String status)` Sets current status
    `void` | `trace(String message)` Prints a trace message
    `void` | `trace(String message, Throwable e)` Prints a trace message
    `void` | `warn(String message)` Prints a warning message
    `void` | `warn(String message, Throwable e)` Prints a warning message

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### sTraceEnabled

          public static boolean sTraceEnabled

    - #### sDF

          public static SimpleDateFormat sDF

    - #### MSGLEVEL_TRACE

          public static final int MSGLEVEL_TRACE

      See Also:
        Constant Field Values

    - #### MSGLEVEL_DEBUG

          public static final int MSGLEVEL_DEBUG

      See Also:
        Constant Field Values

    - #### MSGLEVEL_PROGRESS

          public static final int MSGLEVEL_PROGRESS

      See Also:
        Constant Field Values

    - #### MSGLEVEL_INFO

          public static final int MSGLEVEL_INFO

      See Also:
        Constant Field Values

    - #### MSGLEVEL_STAGE

          public static final int MSGLEVEL_STAGE

      See Also:
        Constant Field Values

    - #### MSGLEVEL_WARN

          public static final int MSGLEVEL_WARN

      See Also:
        Constant Field Values

    - #### MSGLEVEL_ERROR

          public static final int MSGLEVEL_ERROR

      See Also:
        Constant Field Values

    - #### MSGLEVEL_FATAL

          public static final int MSGLEVEL_FATAL

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### getInstance

          public static Progress getInstance()

      Progress default instance
      Returns:
        progress instance

    - #### getInstance

          public static Progress getInstance(Object key)

      Progress instance
      Parameters:
        `key` - an object (typically a problem model) for which the progress is to be returned
      Returns:
        progress instance

    - #### changeInstance

          public static void changeInstance(Object oldKey,
                                            Object newKey)

      Change progress instance for the given key
      Parameters:
        `oldKey` - old instance
        `newKey` - new instance

    - #### removeInstance

          public static void removeInstance(Object key)

      Remove progress instance for the given key
      Parameters:
        `key` - old instance

    - #### getStatus

          public String getStatus()

      Current status
      Returns:
        current status

    - #### setStatus

          public void setStatus(String status)

      Sets current status
      Parameters:
        `status` - current status

    - #### getPhase

          public String getPhase()

      Current phase
      Returns:
        current phase

    - #### setPhase

          public void setPhase(String phase,
                               long progressMax)

      Sets current phase
      Parameters:
        `phase` - phase name
        `progressMax` - maximum of progress bar

    - #### setPhase

          public void setPhase(String phase)

      Sets current phase. Maximum of progress bar is set to 100.
      Parameters:
        `phase` - phase name

    - #### setProgress

          public void setProgress(long progress)

      Update progress bar.
      Parameters:
        `progress` - progress between 0 and progressMax

    - #### getProgress

          public long getProgress()

      Current progress
      Returns:
        current progress

    - #### getProgressMax

          public long getProgressMax()

      Maximum of current progress
      Returns:
        current progress maximum

    - #### incProgress

          public void incProgress()

      Increment current progress

    - #### addProgressListener

          public void addProgressListener(ProgressListener listener)

      Adds progress listener
      Parameters:
        `listener` - a progress listener

    - #### removeProgressListener

          public void removeProgressListener(ProgressListener listener)

      Remove progress listener
      Parameters:
        `listener` - a progress listener

    - #### clearProgressListeners

          public void clearProgressListeners()

      Remove all progress listeners

    - #### save

          public void save()

      Save current progress to the heap memory

    - #### restore

          public void restore()

      Resore the progress from the heap memory

    - #### message

          public void message(int level,
                              String message,
                              Throwable t)

      Prints a message
      Parameters:
        `level` - logging level
        `message` - message to log
        `t` - an exception, if any

    - #### message

          public void message(int level,
                              String message)

      Prints a message
      Parameters:
        `level` - logging level
        `message` - message to log

    - #### trace

          public void trace(String message)

      Prints a trace message
      Parameters:
        `message` - trace message

    - #### debug

          public void debug(String message)

      Prints a debug message
      Parameters:
        `message` - debug message

    - #### info

          public void info(String message)

      Prints an info message
      Parameters:
        `message` - info message

    - #### warn

          public void warn(String message)

      Prints a warning message
      Parameters:
        `message` - warning message

    - #### error

          public void error(String message)

      Prints an error message
      Parameters:
        `message` - error message

    - #### fatal

          public void fatal(String message)

      Prints a fatal message
      Parameters:
        `message` - fatal message

    - #### trace

          public void trace(String message,
                            Throwable e)

      Prints a trace message
      Parameters:
        `message` - trace message
        `e` - an exception, if any

    - #### debug

          public void debug(String message,
                            Throwable e)

      Prints a debug message
      Parameters:
        `message` - debug message
        `e` - an exception, if any

    - #### info

          public void info(String message,
                           Throwable e)

      Prints an info message
      Parameters:
        `message` - info message
        `e` - an exception, if any

    - #### warn

          public void warn(String message,
                           Throwable e)

      Prints a warning message
      Parameters:
        `message` - warning message
        `e` - an exception, if any

    - #### error

          public void error(String message,
                            Throwable e)

      Prints an error message
      Parameters:
        `message` - error message
        `e` - an exception, if any

    - #### fatal

          public void fatal(String message,
                            Throwable e)

      Prints a fatal message
      Parameters:
        `message` - fatal message
        `e` - an exception, if any

    - #### getLog

          public List<Progress.Message> getLog()

      Returns log (list of messages)
      Returns:
        list of logged messages

    - #### getLog

          public String getLog(int level)

      Returns log (list of messages). Only messages with the given level or higher are included.
      Parameters:
        `level` - minimum level
      Returns:
        list of messages

    - #### getHtmlLog

          public String getHtmlLog(int level,
                                   boolean includeDate)

      Returns log in HTML format
      Parameters:
        `level` - minimum level
        `includeDate` - include message date and time in the result
      Returns:
        html list of messages

    - #### getHtmlLog

          public String getHtmlLog(int level,
                                   boolean includeDate,
                                   String fromStage)

      Returns log in HTML format (only messages with the given level or higher are included)
      Parameters:
        `level` - minimum level
        `includeDate` - include message date and time in the result
        `fromStage` - last stage from which the log should begin
      Returns:
        html list of messages

    - #### clear

          public void clear()

      Clear the log

    - #### save

          public void save(Element root)

      Saves the message log into the given XML element
      Parameters:
        `root` - XML root

    - #### load

          public void load(Element root,
                           boolean clear)

      Restores the message log from the given XML element
      Parameters:
        `root` - XML root
        `clear` - clear the log first