Class Counter

  • All Implemented Interfaces:
    Counting, Metric

    public class Counter
    extends java.lang.Object
    implements Metric, Counting
    An incrementing and decrementing counter metric.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private LongAdder count  
    • Constructor Summary

      Constructors 
      Constructor Description
      Counter()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dec()
      Decrement the counter by one.
      void dec​(long n)
      Decrement the counter by n.
      long getCount()
      Returns the counter's current value.
      void inc()
      Increment the counter by one.
      void inc​(long n)
      Increment the counter by n.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Counter

        public Counter()
    • Method Detail

      • inc

        public void inc()
        Increment the counter by one.
      • inc

        public void inc​(long n)
        Increment the counter by n.
        Parameters:
        n - the amount by which the counter will be increased
      • dec

        public void dec()
        Decrement the counter by one.
      • dec

        public void dec​(long n)
        Decrement the counter by n.
        Parameters:
        n - the amount by which the counter will be decreased
      • getCount

        public long getCount()
        Returns the counter's current value.
        Specified by:
        getCount in interface Counting
        Returns:
        the counter's current value