package edu.ntnu.idi.goldfish;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

public class StopWatch {
	
	protected static HashMap<String, Long> starts = new HashMap<String,Long>();
	protected static HashMap<String, Long> timings = new HashMap<String,Long>();
	
	
	public static void start(String name) {
		timings.remove(name);
		starts.put(name, System.currentTimeMillis());
	}
	
	public static void stop(String name) {
		if(!starts.containsKey(name)) {
			System.err.format("have no start timing for %s\n", name);
			return;
		}
		if(!timings.containsKey(name)) {
			timings.put(name, System.currentTimeMillis() - starts.get(name));			
		}
	}
	
	public static String getString(long time) {
		return String.format("%d min, %d sec (%d ms)",
			    TimeUnit.MILLISECONDS.toMinutes(time),
			    TimeUnit.MILLISECONDS.toSeconds(time) - 
			    TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)),
			    time
		);
	}
	
	public static String str(String name) {
		stop(name);
		long time = timings.get(name);
		return getString(time);
	}
	
	public static void print(String name) {
		System.out.format("%s: %s\n", name, str(name));
	}
	
	public static long get(String name) {
		stop(name);
		return timings.get(name);
	}
}

@@ -275,16 +275,120 @@
 %3E();%0A%09%0A%09
+private static String id(String name) %7B%0A        return %22%22+Thread.currentThread().hashCode()+name;%0A    %7D%0A
 %0A%09public
@@ -438,21 +438,25 @@
 .remove(
+id(
 name)
+)
 ;%0A%09%09star
@@ -458,28 +458,32 @@
 %09starts.put(
+id(
 name
+)
 , System.cur
@@ -567,30 +567,34 @@
 containsKey(
+id(
 name))
+)
  %7B%0A%09%09%09System
@@ -686,22 +686,26 @@
 ainsKey(
+id(
 name))
+)
  %7B%0A%09%09%09ti
@@ -714,20 +714,24 @@
 ngs.put(
+id(
 name
+)
 , System
@@ -768,18 +768,19 @@
 get(
+id(
 name))
+)
 ;
-%09%09%09
 %0A%09%09%7D
@@ -1150,21 +1150,25 @@
 ngs.get(
+id(
 name)
+)
 ;%0A%09%09retu
@@ -1362,20 +1362,24 @@
 ngs.get(
+id(
 name)
+)
 ;%0A%09%7D%0A%7D%0A

Add thread id to StopWatch key so it is effectively multithreaded