/*
 *  @author Ranides Atterwim <ranides@gmail.com>
 *  @copyright Ranides Atterwim
 *  @license WTFPL
 *  @url http://ranides.net/projects/assira
 */

package net.ranides.assira.time;

import java.util.Date;
import java.util.Stack;

/**
 *
 * @author ranides
 */
public class TimeStack {

    private final Stack<Long> times = new Stack<>();

    public TimeStack() {
        start();
    }

    final public void start() {
        times.push(new Date().getTime());
    }

    final public void start(int count) {
        for(int i=0; i<count; i++) { times.push(new Date().getTime()); }
    }

    final public long stop() {
        return times.isEmpty() ? 0 : new Date().getTime() - times.pop();
    }

    final public long now() {
        return times.isEmpty() ? 0 : new Date().getTime() - times.lastElement();
    }

    final public long restart() {
        long prev = stop();
        start();
        return prev;
    }

}
