Class Counter


  • public class Counter
    extends Object
    Counting mechanism capable of tracking occurrences and rates.
    • Constructor Summary

      Constructors 
      Constructor Description
      Counter()
      Creates a new counter.
      Counter​(long start, long total, long end)
      Creates a new counter in a specific state.
    • 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 time
        total - total number of items to start with
        end - 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:
        hashCode in class Object