package speiger.src.coreengine.utils.counters.averager;

import java.text.DecimalFormat;

public class TimeAverager extends Averager {
	private static final TimeAverager GLOBAL_TIME_STAMP = new TimeAverager();
	private static final DecimalFormat FORMAT = new DecimalFormat("###,###");
	long start = 0L;
	
	public TimeAverager() {}
	
	public TimeAverager(int count) {
		super(count);
	}
	
	public void stop() { addEntry(System.nanoTime() - start); }
	public void start() { start = System.nanoTime(); }
	
	@Override
	public String toString() {
		long time = getAverage();
		return "Time Stamp: "+FORMAT.format(time / 1000000L)+"ms, ("+FORMAT.format(time / 1000L)+"qs, "+FORMAT.format(time)+"ns)";
	}
	
	public static void startStamp() {
		GLOBAL_TIME_STAMP.start();
	}
	
	public static void stopStamp() {
		GLOBAL_TIME_STAMP.stop();
	}
	
	public static long getAverageTime() { return GLOBAL_TIME_STAMP.getAverage(); }
	
	public static String print() {
		return GLOBAL_TIME_STAMP.toString();
	}
	
	public static void reset() {
		GLOBAL_TIME_STAMP.values.clear();
		GLOBAL_TIME_STAMP.totalValue = 0L;
	}
}