package username.analysis; /** * A class that assists in the analysis of methods. * * @author Samuel A. Rebelsky * @version 1.0 of April 2006 */ public class Analyst { // +--------+-------------------------------------------------- // | Fields | // +--------+ /** A counter for the number of steps an algorithm takes. */ long steps; /** The time the algorithm started. */ long start; /** The time the algorithm started. */ long finish; // +--------------+-------------------------------------------- // | Constructors | // +--------------+ /** * Prepare to analyze an algorithm. */ public Analyst() { this.reset(); } // Analyst() // +---------------------+------------------------------------- // | Bookkeeping Methods | // +---------------------+ /** * Reset the count of the number of steps spent. */ public void reset() { this.steps = 0; this.start = System.currentTimeMillis(); this.finish = 0; } // reset() /** * Count one step. */ public void step() { ++this.steps; } // step() /** * Get the total number of steps used. */ public long steps() { return this.steps; } // steps() /** * Get the elapsed time. */ public long elapsed() { if (this.finish == 0) { return System.currentTimeMillis() - this.start; } else { return this.finish - this.start; } } // elapsed() /** * Stop counting time. */ public void stop() { this.finish = System.currentTimeMillis(); } // stop() } // class Analyst