Class Counter


  • public class Counter
    extends java.lang.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.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(long count)
      Adds the specified number of occurrences to the counter.
      double duration()
      Returns the duration expressed in fractional number of seconds.
      boolean equals​(java.lang.Object obj)  
      void freeze()
      Freezes the counter in the current state including the counts and times.
      int hashCode()  
      void reset()
      Resets the counter, by zeroing out the count and restarting the timer.
      double throughput()
      Returns the number of occurrences per second.
      java.lang.String toString()  
      long total()
      Returns the total number of occurrences counted.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object