package droplauncher.util.windows;

import droplauncher.util.Constants;
import java.util.ArrayList;
import java.util.logging.Logger;

/**
 * Class for tracking newly created tasks in the Windows Tasklist.
 */
public class TaskTracker {

  private static final Logger LOGGER = Logger.getLogger(TaskTracker.class.getName());
  private static final boolean CLASS_DEBUG = (Constants.DEBUG && true);

  private Tasklist previousTasklist;
  private Tasklist currentTasklist;
  private ArrayList<Task> newTasks;

  public TaskTracker() {
    this.previousTasklist = new Tasklist();
    this.currentTasklist = new Tasklist();
    this.newTasks = new ArrayList<>();

    update();
  }

  public Tasklist getCurrentTasklist() {
    return this.currentTasklist;
  }

  public Tasklist getPreviousTasklist() {
    return this.previousTasklist;
  }

  public ArrayList<Task> getNewTasks() {
    return this.newTasks;
  }

  /**
   * Updates both the current and previous tasklists.
   */
  public void update() {
    this.previousTasklist.update();
    this.currentTasklist.update();
  }

  /**
   * Updates the current tasklist and compares it against the previous
   * tasklist to determine which currently running tasks are new.
   */
  public void scanForNewTasks() {
    this.newTasks.clear();

    this.currentTasklist.update();
    if (!this.currentTasklist.equals(this.previousTasklist)) {
      for (Task currTask : this.currentTasklist.getTasks()) {
        boolean isFound = false;
        for (Task prevTask : this.previousTasklist.getTasks()) {
          if (currTask.getPID().equals(prevTask.getPID())) {
            isFound = true;
            break;
          }
        }
        if (!isFound) {
          this.newTasks.add(new Task(currTask));
        }
      }
    }

    if (this.newTasks.size() > 0) {
      this.previousTasklist.update();
    }
  }

}

@@ -1212,16 +1212,94 @@
 re new.%0A
+   *%0A   * @param updatePreviousTasks whether to update the previous tasklist.%0A
    */%0A  
@@ -1314,15 +1314,14 @@
 oid 
-scanFor
+update
 NewT
@@ -1317,32 +1317,59 @@
  updateNewTasks(
+boolean updatePreviousTasks
 ) %7B%0A    this.new
@@ -1878,16 +1878,39 @@
     if (
+updatePreviousTasks && 
 this.new
@@ -1978,10 +1978,324 @@
  %7D%0A  %7D%0A%0A
+  /**%0A   * Updates the current tasklist and compares it against the previous%0A   * tasklist to determine which currently running tasks are new. Note:%0A   * this call does NOT update the previous tasklist.%0A   *%0A   * @see #updateNewTasks(boolean)%0A   */%0A  public void updateNewTasks() %7B%0A    updateNewTasks(false);%0A  %7D%0A%0A
 %7D%0A

Rename "scanForNewTasks" to "updateNewTasks" in "TaskTracker.java"