/*
    Java Libraries https://github.com/foilen/java-libraries
    Copyright (c) 2015-2016 Foilen (http://foilen.com)

    The MIT License
    http://opensource.org/licenses/MIT
    
 */
package com.foilen.smalltools.tools;

import com.foilen.smalltools.exception.SmallToolsException;

/**
 * Some common methods for threads.
 */
public final class ThreadTools {

    /**
     * To help change the name of a thread and revert back later.
     * 
     * <pre>
     * ThreadNameStateTool threadNameStateTool = ThreadTools.nameThread() //
     *         .clear() //
     *         .appendText(threadName) //
     *         .appendText("-") //
     *         .appendObjectText(executionCount) //
     *         .change();
     * 
     * threadNameStateTool.revert();
     * </pre>
     * 
     * 
     * @return the thread changer
     */
    public static ThreadNameStateTool nameThread() {
        return new ThreadNameStateTool();
    }

    /**
     * Write the stack trace of the requested thread to STDOUT.
     * 
     * @param thread
     *            the thread to dump
     */
    public static void printStackTrace(Thread thread) {
        StackTraceElement[] stackTraceElements = thread.getStackTrace();
        for (StackTraceElement stackTraceElement : stackTraceElements) {
            System.out.println(stackTraceElement);
        }
    }

    /**
     * Wait for the specified amount of time.
     * 
     * @param millis
     *            time in milliseconds
     */
    public static void sleep(long millis) {
        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            throw new SmallToolsException("Sleeping interupted", e);
        }
    }

    private ThreadTools() {
    }

}

@@ -218,16 +218,45 @@
 tools;%0A%0A
+import java.util.Map.Entry;%0A%0A
 import c
@@ -1003,28 +1003,375 @@
  of 
-the requested thread
+all threads to STDOUT.%0A     */%0A    public static void printAllStackTraces() %7B%0A        for (Entry%3CThread, StackTraceElement%5B%5D%3E entry : Thread.getAllStackTraces().entrySet()) %7B%0A            System.out.println(entry.getKey().getName());%0A            printStackTrace(entry.getValue());%0A            System.out.println();%0A        %7D%0A    %7D%0A%0A    /**%0A     * Write the stack trace
  to 
@@ -1400,22 +1400,34 @@
  @param 
-thread
+stackTraceElements
 %0A     * 
@@ -1445,22 +1445,13 @@
 the 
-thread to dump
+stach
 %0A   
@@ -1498,33 +1498,8 @@
 ace(
-Thread thread) %7B%0A        
 Stac
@@ -1536,34 +1536,11 @@
 ents
- = thread.getStackTrace();
+) %7B
 %0A   
@@ -1669,32 +1669,274 @@
        %7D%0A    %7D%0A%0A
+    /**%0A     * Write the stack trace of the requested thread to STDOUT.%0A     * %0A     * @param thread%0A     *            the thread to dump%0A     */%0A    public static void printStackTrace(Thread thread) %7B%0A        printStackTrace(thread);%0A    %7D%0A%0A
     /**%0A     * W

add printAllStackTraces