Package org.onlab.util
Class Counter
- java.lang.Object
-
- org.onlab.util.Counter
-
public class Counter extends java.lang.ObjectCounting mechanism capable of tracking occurrences and rates.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(long count)Adds the specified number of occurrences to the counter.doubleduration()Returns the duration expressed in fractional number of seconds.booleanequals(java.lang.Object obj)voidfreeze()Freezes the counter in the current state including the counts and times.inthashCode()voidreset()Resets the counter, by zeroing out the count and restarting the timer.doublethroughput()Returns the number of occurrences per second.java.lang.StringtoString()longtotal()Returns the total number of occurrences counted.
-
-
-
Constructor Detail
-
Counter
public Counter()
Creates a new counter.
-
Counter
public Counter(long start, long total, long end)Creates a new counter in a specific state. If non-zero end time is specified, the counter will be frozen.- Parameters:
start- start timetotal- total number of items to start withend- end time; if non-ze
-
-
Method Detail
-
reset
public void reset()
Resets the counter, by zeroing out the count and restarting the timer.
-
freeze
public void freeze()
Freezes the counter in the current state including the counts and times.
-
add
public void add(long count)
Adds the specified number of occurrences to the counter. No-op if the counter has been frozen.- Parameters:
count- number of occurrences
-
throughput
public double throughput()
Returns the number of occurrences per second.- Returns:
- throughput in occurrences per second
-
total
public long total()
Returns the total number of occurrences counted.- Returns:
- number of counted occurrences
-
duration
public double duration()
Returns the duration expressed in fractional number of seconds.- Returns:
- fractional number of seconds since the last reset
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-