physics
Class Counter

java.lang.Object
  extended by physics.Counter

public final class Counter
extends java.lang.Object

A counter is a mutable ADT used to instrument code to measure the time of blocks of code.


Constructor Summary
Counter(java.lang.String blockName)
          Constructs a Counter with the given block name
 
Method Summary
 void begin()
           
 void end()
           
static java.lang.String getAllResults()
           
 double getAverageTime()
           
static java.util.Collection<Counter> getCounters()
           
 java.lang.String getResult()
           
 int getTotalInvocations()
           
 long getTotalTime()
           
 boolean isRecursionDetected()
           
 void reset()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Counter

public Counter(java.lang.String blockName)
Constructs a Counter with the given block name

Parameters:
blockName - name to use for this counter
Throws:
java.lang.IllegalArgumentException - if blockName is null
java.lang.IllegalArgumentException - if the constructor has already been called with the given blockName
Method Detail

getCounters

public static final java.util.Collection<Counter> getCounters()
Returns:
Collection of Counters containing all Counters ever created

getAllResults

public static final java.lang.String getAllResults()
Returns:
concatenation of c.getResult() for all Counters ever created

begin

public final void begin()

end

public final void end()
Throws:
java.lang.IllegalStateException - if begin() has not been called more times than end() on this counter

reset

public void reset()
Throws:
java.lang.IllegalStateException - if the number of calls to begin() and end() was not equal

getTotalInvocations

public final int getTotalInvocations()
Returns:
this.totalInvocations
Throws:
java.lang.IllegalStateException - if the number of calls to begin() and end() was not equal

getTotalTime

public final long getTotalTime()
Returns:
this.totalTime
Throws:
java.lang.IllegalStateException - if the number of calls to begin() and end() was not equal

getAverageTime

public final double getAverageTime()
Returns:
this.averageTime
Throws:
java.lang.IllegalStateException - if the number of calls to begin() and end() was not equal

isRecursionDetected

public final boolean isRecursionDetected()
Returns:
this.recursionDetected
Throws:
java.lang.IllegalStateException - if the number of calls to begin() and end() was not equal

getResult

public java.lang.String getResult()
Returns:
a String summarizing the results of this counter
Throws:
java.lang.IllegalStateException - if the number of calls to begin() and end() was not equal