package proof.util;

import java.io.PrintStream;

/**
 * Global logger. Keeps track of the progress of the validation.
 *
 * @author Tilo Wiedera
 */
public class ProgressLogger {
  private int progress = 0;
  private int maxProgress = 1;
  private String lastMessage = null;
  private final boolean verbose;
  private static final int SIZE = 32;
  private final PrintStream out;

  /**
   * Creates a new logger.
   *
   * @param out The output stream to use
   * @param verbose Whether to print everything
   */
  public ProgressLogger(PrintStream out, boolean verbose) {
    this.out = out;
    this.verbose = verbose;
  }

  /**
   * Resets the progress to zero.
   *
   * @param maxProgress The progress to reach until finished
   */
  public void reset(int maxProgress) {
    if (maxProgress < 1) {
      throw new IllegalArgumentException("Size must be greater zero.");
    }

    this.maxProgress = maxProgress;
    this.progress = 0;
  }

  /**
   * Prints a message even when {@link #verbose} is disabled.
   *
   * @param message The message to be printed
   */
  public void println(String message) {
    lastMessage = null;
    out.println("\r" + message);
  }

  /**
   * Prints out a single line message. The message is skipped if {@link #verbose} is disabled.
   *
   * @param message The line to be printed
   */
  public void print(String message) {
    if (verbose) {
      if (lastMessage != null) {
        out.print("\r" + String.format("%" + (lastMessage.length() + 6) + "s", ""));
      }

      out.println("[" + String.format("%3d%%", (progress * 99) / maxProgress) + "] "
          + (message == null ? "" : message));
    } else {
      out.print("\r["
          + String.format("%-" + SIZE + "s",
              new String(new char[(progress * SIZE) / maxProgress]).replace("\0", "=")) + "]");
    }
  }

  /**
   * Increases the current progress by one and prints a single line message.
   *
   * @param message The line to be printed
   */
  public void progress(String message) {
    progress();
    print(message);
  }

  /**
   * Increases the current progress.
   */
  public void progress() {
    progress++;

    if (progress > maxProgress) {
      throw new IllegalArgumentException("Maximum progress already reached (" + maxProgress + ").");
    }

    if (!verbose) {
      print(lastMessage);
    }
  }
}

@@ -236,45 +236,8 @@
  1;%0A
-  private String lastMessage = null;%0A
   pr
@@ -265,16 +265,16 @@
 erbose;%0A
+
   privat
@@ -1073,32 +1073,8 @@
 ) %7B%0A
-    lastMessage = null;%0A
     
@@ -1323,135 +1323,8 @@
 ) %7B%0A
-      if (lastMessage != null) %7B%0A        out.print(%22%5Cr%22 + String.format(%22%25%22 + (lastMessage.length() + 6) + %22s%22, %22%22));%0A      %7D%0A%0A
     
@@ -1407,53 +1407,18 @@
 %22%5D %22
-%0A         
  + 
-(
 message
- == null ? %22%22 : message)
 );%0A 
@@ -2093,19 +2093,10 @@
 int(
-lastMessage
+%22%22
 );%0A 

Remove Obsolete Logger Code