package com.codahale.metrics;

import java.util.concurrent.atomic.LongAdder;

An incrementing and decrementing counter metric.
/** * An incrementing and decrementing counter metric. */
public class Counter implements Metric, Counting { private final LongAdder count; public Counter() { this.count = new LongAdder(); }
Increment the counter by one.
/** * Increment the counter by one. */
public void inc() { inc(1); }
Increment the counter by n.
Params:
  • n – the amount by which the counter will be increased
/** * Increment the counter by {@code n}. * * @param n the amount by which the counter will be increased */
public void inc(long n) { count.add(n); }
Decrement the counter by one.
/** * Decrement the counter by one. */
public void dec() { dec(1); }
Decrement the counter by n.
Params:
  • n – the amount by which the counter will be decreased
/** * Decrement the counter by {@code n}. * * @param n the amount by which the counter will be decreased */
public void dec(long n) { count.add(-n); }
Returns the counter's current value.
Returns:the counter's current value
/** * Returns the counter's current value. * * @return the counter's current value */
@Override public long getCount() { return count.sum(); } }